Android - can private intentions be used instead of global ones?

background: I noticed that for regular actions inside, any application can open the actions of my application.

Question: is it possible to allow only my own application (or applications or packages) to send and receive intentions within the same area so that another application cannot receive them or interfere with the application flow?

Example: suppose I have a broadcastReceiver that listens to some intentions, but this intent is only for use by another service / activity, which is either inside my application or inside another application that I created, but I do not want others to be able to use this intention.

please help me.

+4
source share
2 answers

Suppose I have a broadcast receiver that listens to some intention, but this intention is only for use by another service / activity, which is either inside my application or inside another application that I created, but I don’t know so that others can use this intention.

In addition to Renault's kind answer, for your specific requirement above, use the LocalBroadcastManager . You are not only getting the security you are looking for, but also more effective. LocalBroadcastManager is available in the Android Support Package, and AFAIK should return to Android 1.6. Here is an example project using LocalBroadcastManager .

+4
source

setPackage()

Specify an explicit application package name that restricts the components to which this intention will be allowed. If you leave the default value null, all components in all applications are taken into account. If not null, Intent can only match the components in a given application package.

or you can use setSelector() , but not both.

+6
source

Source: https://habr.com/ru/post/1401811/


All Articles