android.intent.action.SCREEN_ON和android.intent.action.SCREEN_OFF待機廣播在TV android開發過程中,不響應原因.

待機廣播,又叫屏幕喚醒廣播:android.intent.action.SCREEN_ON和android.intent.action.SCREEN_OFF

在使用過程中需要主要以下兩點:

1.需要在AndroidManifest.xml添如下權限:

<uses-permission android:name="android.permission.WAKE_LOCK"/>

2.這個廣播不能靜態註冊及不能在AndroidManifest.xml文件中註冊.

改爲動態註冊,建議在Application中或者main中註冊廣播,動態註冊廣播方法如下:

//廣播
public class BootBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(ACTION_BOOT)) { //開機啓動完成後,要做的事情
            mLogger.i(TAG, "ACTION_BOOT BootBroadcastReceiver onReceive(), Do thing!");
            Intent intent1 = new Intent(context, IptvSettingsService.class);
            context.startService(intent1);
        }
}
// 在Application中或者main中onCreate中添加加如下代碼
IntentFilter mIntentFilter = new IntentFilter(); 
mIntentFilter.addAction("android.intent.action.SCREEN_ON");// 添加關閉廣播
BootBroadcastReceiver mBootBroadcastReceiver = new BootBroadcastReceiver(); // 
registerReceiver(mBootBroadcastReceiver,mIntentFilter);

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章