Android Broadcast Security

有些话、适合烂在心里 提交于 2019-12-20 06:24:58

问题


In android, you can set the action of a broadcast to almost anything (save system actions.) My question is how can you prevent other apps from spoofing your broadcasts? Say you have an action called "com.a.b.c". Other applications should receive com.a.b.c, but they shouldn't be able to send com.a.b.c. How can that be done?

Also, I seek clarification of permissions that deal with broadcast reception. I find the Android documentation a bit confusing with this. Is there a way to make a permission that other applications have to have to receive com.a.b.c? Like specifying com.a.b.cpermission in the manifest for others to use.


回答1:


You can use LocalBroadcastManager https://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager.html

Also you can define permission in the manifest. And use http://developer.android.com/reference/android/content/Context.html#sendBroadcast%28android.content.Intent,%20java.lang.String%29 to send broadcast, then only apps which requested your "com.a.b.c" permission will receive. But this is public api to your app, be careful this way.



来源:https://stackoverflow.com/questions/17795987/android-broadcast-security

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!