中止/取消广播
我想要的:我想成为第一个接收短信广播的人,并且如果短信仅对我感兴趣,我想取消广播,以便广播不会到达任何其他应用程序/接收器(默认消息应用程序等) 。 我所知道的是:
- SmsDisptacher.java 使用可以取消/中止的orderedBroadcasts。
我不知道的是:
- 是否可以为其他应用程序/接收器(即除了您自己之外)取消订购广播。
我已经尝试过第一个接收广播:
- intent-filter android:priority="1000"
我已经尝试过取消广播:
- AbortBroadcast();
- BroadcastReceiver.setResultCode(RESULT_CANCELED)
- clearAbortBroadcast()
What I want: I want to be the first to receive the Sms Broadcast and I want to cancel the broadcast if SMS is of my interest only, so that The broadcast doesn't reach any other app/receiver (Default messaging app etc.).
What I know is:
- SmsDisptacher.java uses orderedBroadcasts that can be can canceled/aborted.
What I don't know is:
- If orderedBrodcasts can be canceled for other apps/receivers i.e other than yourself.
what I have tried for being the first to receive the Broadcast:
- intent-filter android:priority="1000"
What i have tried for canceling broadcast already:
- AbortBroadcast();
- broadcastReceiver.setResultCode(RESULT_CANCELED)
- clearAbortBroadcast()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这当然是可能的。
在清单中注册您的接收器,如下所示:
在接收器的 onReceive 方法中写入:
请记住在清单中设置接收短信的权限,如下所示:
如果没有正确的权限集,它将默默失败并显示以下 logcat 消息:
最后,它是可能另一个应用程序已经注册了比您的优先级更高的接收器,因此它会在您取消广播之前接收广播。因此,如果所有其他方法都失败,请尝试尝试更高的优先级值。
It is certainly possible.
Register your receiver in your manifest like this:
In your receiver's onReceive method write:
Remember to set the permission to receive sms messages in the manifest like this:
Without the correct permission set it will fail silently with the following logcat message:
Finally, it is possible that another application has registered a receiver with an even higher priority than yours, and that it therefore receives the broadcast before you cancel it. So if all else fails, try experimenting with higher priority values.
这是可能的,我做了一个教程,请检查此处和此处
只需中止层次结构顶部的广播
it's possible to do that, i did a tutorial check it please here and here
just abort the broadcast on the top of the hierarchy
得到了我的答案 http://groups.google.com/group/android- Developers/browse_thread/thread/78fecbc156f4a1ea 这是不可能的。
Got my answer http://groups.google.com/group/android-developers/browse_thread/thread/78fecbc156f4a1ea Its not possible.