我是靠谱客的博主 甜美黄蜂,这篇文章主要介绍Android 高版本广播BroadCastReceiver,现在分享给大家,希望可以做个参考。

1:发送广播  

 Intent intent = new Intent();
intent.setAction("fanghq");
// 低版本时不需要该操作,如果是同一个APP,包名使用的是该APP包名,如果是另一个APP,包名直接使用另一个APP的就好
intent.setComponent(new ComponentName("com.thzy.jpushtext001","com.thzy.jpushtext001.MyReceiver002"));
sendBroadcast(intent);

2:接收广播

自定义广播继承BroadcastReceiver,并实现onReceive(Context context,Intent intent)方法。

动态或者静态声明广播。

静态:

<receiver
android:name=".MyReceiver002"
android:enabled="true"
android:exported="true">
<intent-filter>
//action 和上面发送广播时定义保持一致
<action android:name="fanghq" />
</intent-filter>
</receiver>

最后

以上就是甜美黄蜂最近收集整理的关于Android 高版本广播BroadCastReceiver的全部内容,更多相关Android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(110)

评论列表共有 0 条评论

立即
投稿
返回
顶部