Android deep linking schema: match both http and h

2019-04-19 18:32发布

问题:

I want my app to open on http://www.example.com and https://www.example.com.

This works:

            <data
                android:host="www.example.com"
                android:path="/"
                android:scheme="http"/>

            <data
                android:host="www.example.com"
                android:path="/"
                android:scheme="https"/>

Is it possible to catch both with one entry? I tried:

            <data
                android:host="www.example.com"
                android:path="/"
                android:scheme="http*"/>

but this catches only the http link, not the https one.

So I know how I can handle bot variants, but want to use the most concise writing possible.

回答1:

This seems to do the trick for me:

<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="http" />
    <data android:scheme="https" />
    <data android:host="www.mywebsite.com" />
    <data android:pathPrefix="/mypage.php" />
</intent-filter>


回答2:

You can use seperate <intent-filter> for both

<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:host="www.example.com"
            android:path="/"
            android:scheme="http"/>     
</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:host="www.example.com"
            android:path="/"
            android:scheme="https"/>     
</intent-filter>