Is it possible to register two actions within one <intent-filter> for Activity

Igor Čordaš picture Igor Čordaš · Mar 21, 2014 · Viewed 8.6k times · Source

I wanted to register my launcher activity so it could be started by both clicking on icon and opening link with a custom scheme. I managed to make it work but am questioning is this correct way. This is the relevant part of my manifest:

  <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="my.sheme" />
        </intent-filter>

This does work but I was wondering should I register both actions under same intent filter. I tried just moving tags from second filter to the first one but then my activity doesn't show icon on install. Is it possible to do it this way and I just made some small syntax error(or broke some undocumented order of declaration rule) or is my thinking completely wrong on this and there are deeper reasons why this doesn't work?

NOTE:I do set android:exported="true"but android.intent.action.MAIN works even without it because it becomes exported anyway if you use action.MAIN

Answer

akirk picture akirk · Mar 21, 2014

As the Android documentation states:

When you want to handle multiple kinds of intents, but only in specific combinations of action, data, and category type, then you need to create multiple intent filters.

Otherwise you can group them into one intent-filter.