"Private" intent filter for self-use applications

I created a file explorer and registered

<action android:name="android.intent.action.GET_CONTENT" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.OPENABLE" /> 

But I do not want my internal file explorer to be shown to the user to select when another application sends an implicit intent with the category "Openable". How can i do this? Should I just create my own action name?

I don’t have it explicitly because I want the user to select a different file explorer in their application.

+4
source share
5 answers

I agree with Chris Stratton and Tal Kanel . Instead, you can use certain “data” in your intent filter. The documentation says:

An Intent that does not contain either a URI or a test data type only if the filter does not specify the URI or data types in the same way.

So, if the intent has the category “Open” and does not have a data part that matches your data part of a particular filter, your internal file explorer will not be displayed to the user.

+1
source

If it is important that only your own application can run one of your components, set the exported attribute to false for this component in the manifest.

+2
source

if you ask me - I think that it’s best for your situation to create your own filter of intentions (as you spoke in your question), because if you announce your activity to receive a system built into the broadcast, it means. so what is the point using this built-in translation if you "break his contract" from a system point of view and want to ignore it in some cases?

if you decide to use this built-in filter anyway, although I suggested that the way to achieve what you want is:

register the recipient not in the manifest, but in the onCreate () method of your first run and unregister in onDestroy ().

thus, your activity will not be registered if none of your actions is in the foreground - this is close to the state which application is close to the point of view of users.

if you don’t know how to do it like this:

 private BroadcastReceiver mMyCustomReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); registerReceiver(mMyCustomReceiver, IntentFilter.create(YOUR_FILTER_ACTION_COMMAND, YOUR_FILTER_DATA_TYPE)); } @Override protected void onDestroy() { unregisterReceiver(mMyCustomReceiver); super.onDestroy(); } 
+1
source

You can use the "activity alias" to make a "copy" of the activity using android: exported = "false" and personal intentions?

+1
source

If you are ready to invoke your activity using an explicit intent (i.e., specify the name of the target component), you can omit the intent filter for this action.

0
source

All Articles