开发者

turn lock off and screen on after sleep

My app has an alarm which triggers after a period during which the phone has gone to sleep. I want the sliding lock to be overridden when the alarm is triggered so that the current view becomes immediately visible. At the moment when the alarm is triggered the code starts to run (activates the camera) but the screen remains blank. If I press the power key and then slide the lock the live camera screen comes into view. I am calling the following code to try to wake up the device and show the screen but it doesn't seem to make any difference. The last thing I tried was to add the userActivity call, now I have run out of things to try and hope someone has some experience of how to do this.

public void setWakeLock(WakeLock wakeLock) {
        PowerManager pm  = (PowerManager) getSystemService(Context.POWER_SERVICE);

        wakeLock = pm.newWakeLock(PowerM开发者_C百科anager.SCREEN_BRIGHT_WAKE_LOCK | 
                         PowerManager.ACQUIRE_CAUSES_WAKEUP, "MyWakeLock");
        if ((wakeLock != null) &&           // we have a WakeLock
                (wakeLock.isHeld() == false)){
        wakeLock.acquire();
        pm.userActivity(SystemClock.uptimeMillis(), true);

        }
    }


Check the android.app.KeyguardManager.KeyguardLock class. You need to call disableKeyguard() from there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜