How to determine the sender of Broadcast Intent

左心房为你撑大大i 提交于 2019-11-29 14:00:47

No.

If you only want to do something when an action was broadcast by another app (i.e. not yours), I imagine it should be easy to determine that your app didn't send this broadcast, and therefore it was someone else..

If all you care about is if it was sent by your app or not, what you can do is add an extra to the Intent every time you create one. For example:

broadcastIntent.putExtra('com.android.app.EXTRA_APP_CREATED', true)

Then, when you receive the broadcast, you can check

if (intent.getExtra('com.android.app.EXTRA_APP_CREATED', false) { ... }

To see if you created the intent.

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