Android广播权限_广播四

来源:互联网 发布:网络诈骗被骗者心理 编辑:程序博客网 时间:2024/06/14 05:50
1.发送广播时可以自定义发送有权限的广播,这样在广播接收器接收广播时,也要配置有权限才能监听到有权限的广播
2.发送广播都是使用Activity的父类ContextWrapper中的函数发送的
(1)发送无权限广播
sendBroadcast(intent); //发送普通广播
sendBroadcast(intent, null); //发送普通广播
sendOrderedBroadcast(intent, null);//发送有序广播
(2)发送权限为far.sight的广播,广播权限用字符串表示,该字符串中必须要用一个点,否则不会成功,如"far.sgiht"就是合法的,而用"farsight"是不合法的。
sendBroadcast(intent,"far.sight"); //发送普通广播,权限为far.sight
sendOrderedBroadcast(intent, "far.sight");//发送有序广播,权限为far.sight
3.在接收有权限的广播时,必须要在广播接收器所在的项目的AndroidManifest.xml的</manifest>标签中配置
<uses-permission android:name="权限" />
<permission android:protectionLevel="normal" android:name="权限" />
例:
如果要监听权限为far.sight的广播,则配置为
<uses-permission android:name="far.sight" />
<permission android:protectionLevel="normal" android:name="far.sight" />
原创粉丝点击