简体   繁体   中英

Intent-Filter either allows launching via URL or app appearing in the Android launcher

I want my app to be able to be launched via the launcher and also when a user visits a website. Using the following code in my AndroidManifest.xml makes the app visible in the launcher but won't launch when I visit app.example.org :

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    <action android:name="android.intent.action.VIEW"></action>
</intent-filter>
<intent-filter>
    <category android:name="android.intent.category.DEFAULT"></category>
    <category android:name="android.intent.category.BROWSABLE"></category>
    <data
        android:host="app.example.org"
        android:scheme="https"></data>
</intent-filter>

however when I use the following code, the app will be opened by visiting the url BUT won't appear in the launcher:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    <action android:name="android.intent.action.VIEW"></action>
    <category android:name="android.intent.category.DEFAULT"></category>
    <category android:name="android.intent.category.BROWSABLE"></category>
    <data
        android:host="app.example.org"
        android:scheme="https"></data>
</intent-filter>

Does anyone have an idea?

So the good thing is, whenever you post something to SO you will find the answer 5 minutes later yourself - so here it is:

Move the line

<action android:name="android.intent.action.VIEW"></action>

from the intent-filter responsible for the launcher, to the intent-filter responsible for the web bonanza, which will look like this:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
    <category android:name="android.intent.category.DEFAULT"></category>
    <category android:name="android.intent.category.BROWSABLE"></category>
    <action android:name="android.intent.action.VIEW"></action>
    <data
        android:host="app.example.org"
        android:scheme="https"></data>
</intent-filter>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM