How to create / disable the intent filter in a programmable way?

I have three kinds of activity and three Intent Filters for them in the Android manifest.

<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".firstActivity" android:theme="@style/AppTheme" android:label="@string/first"> <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> </intent-filter> </activity> <activity android:name=".secondActivity" android:theme="@style/AppTheme" android:label="@string/second"> <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> </intent-filter> </activity> <activity android:name=".thirdActivity" android:theme="@style/AppTheme" android:label="@string/third"> <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> </intent-filter> </activity ></application> 

How to disable programmable filters depending on parameters? Or can I create new intent filters for code?

Thanks.

+6
android intentfilter
source share
3 answers

You cannot enable, disable, or create <intent-filter> programmatically.

However, in your case, you only have one <intent-filter> for each component. In this case, you can enable and disable the component programmatically, through PackageManager and setComponentEnabledSetting() . In your case, enabling or disabling activity will have the same basic effect as enabling or disabling its <intent-filter> .

+19
source share

The intent filter is an instance of the IntentFilter class. However, since the Android system must be aware of the capabilities of the component before it can run this component, intent filters are usually not configured in the Java code, but in the application manifest file (AndroidManifest.xml) as elements. ( One exception is filters for broadcast receivers that are registered dynamically by calling Context.registerReceiver (); they are directly created as IntentFilter objects.)

source: http://developer.android.com/guide/components/intents-filters.html

Also see this: https://stackoverflow.com/a/312977/

+4
source share

If your activity had multiple intent-filter , you can disable a specific intent-filter by creating activity-alias with intent-filter , which you want to disable and disable only the activity alias. See: https://developer.android.com/guide/topics/manifest/activity-alias-element.html

0
source share

All Articles