send broadcast intent to only one application without using explicit intent

允我心安 提交于 2020-01-04 18:16:52

问题


I have a problem. I'm doing a external android service where applications can register to it to receive information. The information come back to the apps from the service via broadcast, and receive it with a broadcastReceiver.

The problem is if I do sendBroadcast, any app can listen the information that is for others, I can use the category on the intent filter, but both apps can have it the same category, or a malicous app can do this one on pourpose.

A solution is explicit intents, but for this I need the app to register with the package and the class where it will receive the intent. I don't like this solution.

I think there exists another solution, because GCM does so similar and doesn't need anything but the broadcastreceiver

I add a small diagram:

Does the possibility exist to send a broadcast only to a specific app, without defining the class??

How GCM does it?


回答1:


If I understand your question correctly, your concern is in how to have the service send information back to the clients, securely.

In that case, you can use a PendingIntent.

A PendingIntent is Parcelable, and so it is easy for the clients to deliver to the service. Your service can track these and send() them as needed, supplying additional data to be put into the Intent extras for the Intent wrapped by the PendingIntent.

The component that will respond to the PendingIntent -- activity, service, or receiver -- does not need to be exported.



来源:https://stackoverflow.com/questions/21141893/send-broadcast-intent-to-only-one-application-without-using-explicit-intent

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