1.广播消息发送端:
1.1 在需要发送广播消息的地方调用下述接口:
private void testSendBroadcast(Activity act){
//create an intent with an action
String str_pass = "android.intent.action.CAMERA_PASS";
Intent intent = new Intent(str_pass);
intent.putExtra("msg","PASS");
//send Broadcast
act.sendBroadcast(intent);
}
2.广播消息接收端:
2.1 在AndroidManifest.xml文件中的<Activity></Activity>后面增加以下代码:
<receiver android:name="SetBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.CAMERA_PASS" />
</intent-filter>
</receiver>
2.2 项目代码文件存放处新建SetBroadcastReceiver.java文件(文件名可自行命名),然后在该文件下写入下述代码:
<