本文介绍了如何检查是否广播发送具有自定义权限发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的应用程序正在开始广播插件。我已经成功地添加自定义权限,所以只有应用程式上的权限的用户可以接收广播。
I have a plugin for my app that is started with a BroadCast. I already managed to add a custom permission, so only apps with the permission can receive the broadcast.
不过,我不知道如何实现,更重要的部分:?我如何检查,如果发件人有一个自定义权限,所以只有我主要的应用程序可以发送广播
However, I have no idea how to achieve the more important part: How can I check, if the sender has a custom permission, so only my main app can send the broadcast?
我知道这是可能的,但我不知道该怎么做。
I know this is possible, but I don't know how to do it.
谢谢!
推荐答案
请尝试使用:
Context ctx = ...;
int result = ctx.checkCallingPermission("your.permission.goes.here");
if (PackageManager.PERMISSION_GRANTED == result) {
// Do your stuff here
}
在您广播接收机。或声明的权限在AndroidManifest.xml中,你定义你的接收器。
in your broadcast receiver. Or declare the permission in your AndroidManifest.xml where you define your receiver.
<reciever android:name="your.receiver.goes.here"
android:permission="your.permission.goes.here" />
这篇关于如何检查是否广播发送具有自定义权限发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!