1. 程式人生 > >AIR 開發 Android 應用儲存螢幕常亮的方法

AIR 開發 Android 應用儲存螢幕常亮的方法

//在釋出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();  //退出程式
}