AIR 開發 Android 應用儲存螢幕常亮的方法
阿新 • • 發佈:2019-02-01
//在釋出air for android 的設定面板中勾選 WAKE_LOCK 許可權 NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate); NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate); NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys); function handleActivate(event:Event):void { NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE; //保持常亮 一直喚醒的狀態 } function handleDeactivate(event:Event):void { NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.NORMAL; //回覆正常 } function handleKeys(event:KeyboardEvent):void { if(event.keyCode == Keyboard.BACK) NativeApplication.nativeApplication.exit(); //退出程式 }