Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many scheme & host tags can come under intent-filter in android manifest

Need more info regarding intent-filter tag specified in manifest. I am aware that we can specify data in two forms:

<intent-filter>
     <data android:host="com.myHost" android:scheme="content"/>
</intent-filter>

AND :

<intent-filter>
     <data android:scheme="content"/>
     <data android:host="com.myHost"/>
</intent-filter>

But I wish to know can several combinations exist, like

<intent-filter>
         <data android:host="com.myHost" android:scheme="content"/>
         <data android:scheme="content"/>
         <data android:host="com.myHost1"/>
</intent-filter>

OR:

<intent-filter>
         <data android:host="com.myHost" android:scheme="content"/>
         <data android:scheme="content"/>
         <data android:host="com.myHost1"/>
         <data android:scheme="content"/>
         <data android:host="com.myHost2"/>
</intent-filter>

In the last case, I wish to know firstly if this can exist & how is it decided that which host to be used for which scheme, as the data tags containing scheme & host can occur in any order.

Please help.

like image 246
AndroidGuy Avatar asked May 16 '13 09:05

AndroidGuy


People also ask

What is central sector scheme?

Central sector schemes are 100% funded by the Union government and implemented by the Central Government machinery. In Centrally Sponsored Scheme (CSS) a certain percentage of the funding is borne by the States and the implementation is by the State Governments.


2 Answers

I am aware that we can specify data in two forms

Do not use content for a scheme, unless you truly mean that you are creating an activity in support of a ContentProvider.

But I wish to know can several combinations exist

If your filter has just one attribute for <data>, you definitely can have different values, such as this from the Contacts app:

    <activity
        android:name=".activities.ShowOrCreateActivity"
        android:theme="@android:style/Theme.Translucent.NoTitleBar">

        <intent-filter>
            <action android:name="com.android.contacts.action.SHOW_OR_CREATE_CONTACT" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="mailto" />
            <data android:scheme="tel" />
        </intent-filter>
    </activity>

Also, one component can have several <intent-filter> elements, each of which is logically OR'd with the others (any Intent matching any filter is a match for the component). So for more complex scenarios, where you have 2+ attributes per <data> element, I would be inclined to put those in separate <intent-filter> elements.

how is it decided that which host to be used for which scheme

Any match is considered good. You would examine the Intent yourself to learn more about what it contains.

like image 50
CommonsWare Avatar answered Oct 13 '22 04:10

CommonsWare


Complementing @CommonsWare answer, it appears that you cannot use two <data> tags if you are not so specific.

A) In one of my apps I can have:

<data android:scheme="myAppScheme1"/>

B) And

<data android:scheme="myAppScheme2" android:host="host2"/>

C) But the following will ignore the first tag (using myAppScheme1://whatever URI won't work):

<data android:scheme="myAppScheme1"/>
<data android:scheme="myAppScheme2" android:host="host2"/>

D) However if I complement the first scheme it will work for both URIS:

<data android:scheme="myAppScheme1" android:host="host1"/>
<data android:scheme="myAppScheme2" android:host="host2"/>

Probably if you really need the case C), you'll better create two intent-filters

like image 25
htafoya Avatar answered Oct 13 '22 03:10

htafoya