1. 一鍵啟動的過程
1.1 對于global key, 系統(tǒng)會根據(jù)global_keys.xml發(fā)送消息給某個組件
<key keyCode="KEYCODE_TV" component="com.thisway.app_0001_leddemo/.MyBroadcastReceiver" />
1.2 APP應該注冊廣播消息的接收者
1.2.1 編寫B(tài)roadcastReceiver派生類, 實現(xiàn)消息處理函數(shù)
package com.thisway.app_0001_leddemo;//注意包名,可以是自己的報名,但是后面的實驗當中的操作需要根據(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 注冊派生類: 修改 AndroidManifest.xml,添加下列代碼,實現(xiàn)靜態(tài)注冊
<receiver android:name=".MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.GLOBAL_BUTTON"/>
</intent-filter></receiver>
1.3 然后在該組件中啟動app