send broadcast intent to only one application with

2019-07-15 12:14发布

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:

enter image description here

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

How GCM does it?

1条回答
再贱就再见
2楼-- · 2019-07-15 13:14

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.

查看更多
登录 后发表回答