在Activity的onCreate()中:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
// onResume() 中调用:

mWakeLock.acquire();
//  onPause() 中调用释放WakeLock对象
mWakeLock.release();

方法二: use the window flag FLAG_KEEP_SCREEN_ON

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

相关文章:

  • 2021-08-02
  • 2022-01-17
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
猜你喜欢
  • 2021-07-16
  • 2022-12-23
  • 2022-01-08
  • 2021-11-21
  • 2022-12-23
  • 2021-06-18
  • 2022-02-24
相关资源
相似解决方案