Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 357
Igor Čordaš Avatar asked Mar 21 '14 16:03

Igor Čordaš


People also ask

Can an activity have multiple intent filters?

To inform the system which implicit intents they can handle, activities, services, and broadcast receivers can have one or more intent filters.

Is it possible to give more than one action in an intent Mcq?

No, you can have multiple actions. But they need to match any combination with a category. An action android. intent.

What is action in 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.

Which components can you specify in an intent filter?

The intent filter specifies the types of intents that an activity, service, or broadcast receiver can respond. Intent filters are declared in the Android manifest file.


1 Answers

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.

like image 74
akirk Avatar answered Oct 10 '22 16:10

akirk