android 进程间通信之广播消息(Broadcast)

本文介绍了Android系统中的进程间通信方式——广播消息(Broadcast)。内容包括如何创建广播发送端,通过调用特定接口发送广播,以及构建广播接收端,在AndroidManifest.xml中注册接收器来捕获消息。
摘要由CSDN通过智能技术生成


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文件(文件名可自行命名),然后在该文件下写入下述代码:

<

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值