1. 一鍵啟動(dòng)的過(guò)程
1.1 對(duì)于global key, 系統(tǒng)會(huì)根據(jù)global_keys.xml發(fā)送消息給某個(gè)組件
<key keyCode="KEYCODE_TV" component="com.thisway.app_0001_leddemo/.MyBroadcastReceiver" />
1.2 APP應(yīng)該注冊(cè)廣播消息的接收者
1.2.1 編寫B(tài)roadcastReceiver派生類, 實(shí)現(xiàn)消息處理函數(shù)
package com.thisway.app_0001_leddemo;//注意包名,可以是自己的報(bào)名,但是后面的實(shí)驗(yàn)當(dāng)中的操作需要根據(jù)包名修改import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.widget.Toast;/*** Created by alienware on 2017/5/12.*/public class MyBroadcastReceiver extends BroadcastReceiver{ @Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "myReceiver receive", Toast.LENGTH_SHORT).show();
Intent intentNewTask=new Intent(context,MainActivity.class);
intentNewTask.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentNewTask);
}
}
1.2.2 注冊(cè)派生類: 修改 AndroidManifest.xml,添加下列代碼,實(shí)現(xiàn)靜態(tài)注冊(cè)
<receiver android:name=".MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.GLOBAL_BUTTON"/>
</intent-filter></receiver>
1.3 然后在該組件中啟動(dòng)app
網(wǎng)友評(píng)論