1. 一键启动的过程
1.1 对于global key, 系统会根据global_keys.xml发送消息给某个组件
<key keyCode="KEYCODE_TV" component="com.thisway.app_0001_leddemo/.MyBroadcastReceiver" />
1.2 APP应该注册广播消息的接收者
1.2.1 编写BroadcastReceiver派生类, 实现消息处理函数
package com.thisway.app_0001_leddemo;//注意包名,可以是自己的报名,但是后面的实验当中的操作需要根据包名修改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,添加下列代码,实现静态注册
<receiver android:name=".MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.GLOBAL_BUTTON"/>
</intent-filter></receiver>
1.3 然后在该组件中启动app