AIR for Android and Wake Lock with KeyguardI have an application where I want to prevent sleeping, but I still want the user to be able to lock the screen using the power button. The conventional wisdom is to do something like the following: protected function view1_addedToStageHandler(event:Event):void { NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE; stage.addEventListener(Event.DEACTIVATE, releaseWakeLock); } protected function releaseWakeLock(event:Event):void{ NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.NORMAL; } This, however, does not work. The problem seems to be that the Android OS receives the sleep event before the AIR application does, and therefore when the user presses the power button again, the screen is not locked. The solution, fortunately, is simple – just don’t enable the DISABLE_KEYGUARD permission in the android manifest. The comments from Adobe say to toggle both DISABLE_KEYGUARD and WAKE_LOCK together, but everything seems to work as I would expect with just WAKE_LOCK. |
|