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?
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
isParcelable
, and so it is easy for the clients to deliver to the service. Your service can track these andsend()
them as needed, supplying additional data to be put into theIntent
extras for theIntent
wrapped by thePendingIntent
.The component that will respond to the
PendingIntent
-- activity, service, or receiver -- does not need to be exported.