Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create/disable intent-filter programmatically?

I have three 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 can I disable the intent filters programmatically depending on some options? Or how can I create new intent filters in code?

Thanks.

like image 748
mamutido Avatar asked Jan 03 '13 15:01

mamutido


People also ask

What is an intent filter?

An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to receive. For instance, by declaring an intent filter for an activity, you make it possible for other apps to directly start your activity with a certain kind of intent.

Where do I find the intent filter code in Android manifest?

Intent Filter Code Inside Android Manifest: The code of Intent Filter is used inside AndroidManifest.xml file for an activity. You can see it: open manifests folder >> open AndroidManifest.xml file. Table Of Contents. 1 Syntax of Intent Filters: 2 Attributes of Intent Filter: 3 Elements In Intent Filter:

How do I know if multiple intent filters are compatible?

If multiple intent filters are compatible, the system displays a dialog so the user can pick which app to use. An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to receive.

How do I advertise implicit intents in my App?

To advertise which implicit intents your app can receive, declare one or more intent filters for each of your app components with an <intent-filter>element in your manifest file. Each intent filter specifies the type of intents it accepts based on the intent's action, data, and category.


1 Answers

You can neither enable, disable, or create <intent-filter>s programmatically.

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

like image 128
CommonsWare Avatar answered Sep 20 '22 15:09

CommonsWare