8

TL;DR Can i use two actions and two categories in one intent-filter?

My app is made up of one activity and five fragments. I have an Intent Filter in this activity.

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

Today, I saw a lint message "App is not indexable by Google..." around the application tag in manifest file. So, I did some searching and came to know that you can use this to index your app through google search. If an android user browses web link "www.example.com/myapp" from chrome/systemBrowser, he will be taken to my app instead of web page. right?

Now, I have to add an ActionView to the activity. and, my intent-filter will become,

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.LAUNCHER" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http" android:host="www.example.com" android:pathPrefix="/myapp" />
 </intent-filter>

But, I have read that using two actions is not good. It is a Logical OR operation. Intent-Filter will match only one of them:

    1. an intent with MAIN action and LAUNCHER Category
    1. an intent with MAIN action and BROWSABLE Category
    1. an intent with VIEW action and LAUNCHER Category
    1. an intent with VIEW action and BROWSABLE Category

As i understand it, It should open app on device with first option, and when a user browses the browser with provided "www.example.com/myapp", it should use first and fourth option to open the app from link.

I have looked at this question, but i need to be sure with an example.

It is confusing. I might be entirely wrong, please guide me.

1 Answer 1

20

By the help of someone from SO Chat, I was told to use separate intent-filters

    <activity
        android:name=".activities.MainActivity"
        android:label="@string/app_name">

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

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" android:host="www.example.com" android:pathPrefix="/prefix" />
        </intent-filter>

    </activity>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.