使用PowerManager后,我的设备再也不会进入睡眠模式

时间:2014-06-09 14:21:23

标签: android powermanager

我正在做一个应用程序,我在三星Galaxy Y(Android 2.3.6)和Engel平板电脑7“(Android 4.0.x)设备上进行测试。

在我的应用程序代码中,我使用此代码段来唤醒设备(当它们处于睡眠模式时)并且运行良好,但现在我的问题是,唤醒后它们再也不会进入睡眠模式了,只有按下硬件按钮才能进入。 有人知道如何在使用PowerManager后设置默认能量设置吗?

KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); 
    final KeyguardManager.KeyguardLock kl = km .newKeyguardLock("MyKeyguardLock"); 
    kl.disableKeyguard(); 

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 
    WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
                                     | PowerManager.ACQUIRE_CAUSES_WAKEUP
                                     | PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
    wakeLock.acquire();

2 个答案:

答案 0 :(得分:0)

试试这个:

void wakeUpGirls() {
    if (wakeLock != null) {
     wakeLock.release();
    }
   KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
   KeyguardLock keyguardLock = km.newKeyguardLock("TAG");
   getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

   keyguardLock.disableKeyguard();
   PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
   wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK 
               | PowerManager.ACQUIRE_CAUSES_WAKEUP 
               | PowerManager.ON_AFTER_RELEASE 
               | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "MyWakeLock");

   wakeLock.acquire();
}

void sleepGirls() {
    if (wakeLock != null) {
      wakeLock.release();
        wakeLock = null;
   }
}

答案 1 :(得分:0)

使用它适合我的那个

  PowerManager powermanager=  ((PowerManager)getSystemService(Context.POWER_SERVICE));
  WakeLock wakeLock = powermanager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
            wakeLock.acquire(9000);
            wakeLock.release

  KeyguardManager km =(KeyguardManager)getSystemService(KEYGUARD_SERVICE);
            k1 = km.newKeyguardLock("IN");
            k1.disableKeyguard();