Ashwin
Ashwin

Reputation: 13517

How to restrict a user defined intent to your app

If I create a user defined intent filter for a specific app, then how do I restrict or make it available from being accessed by other apps.

<intent-filter>
    <action android:name="com.opentable.action.RESERVE"/>

In this case the particular activity or broadcast reciever that is registered to com.opentable.action.RESERVE will be invoked. Is there a way that I can specify if com.opentable.action.RESERVE can be called from other apps as well or only restrict it my app?

Upvotes: 2

Views: 665

Answers (1)

seeming.amusing
seeming.amusing

Reputation: 1179

If you are defining a custom Intent action that should be internal to your application, then you do not need to define it in your Manifest file.

For example, in an app, I am using the LocalBroadcastManager as part of a dispatcher pattern implementation. I would register a BroadcastReceiver implementation this way:

IntentFilter filter = new IntentFilter();
filter.addAction("com.example.android.MY_ACTION");
LocalBroadcastManager.getInstance(context).registerReceiver(receiver, filter);

Then when I run the following code, my receiver will receive the locally broadcasted Intent:

Intent intent = new Intent();
intent.setAction("com.example.android.MY_ACTION");
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);

This way you do not need to publish your actions for other apps to possibly interact with.

Upvotes: 4

Related Questions