Android Deeplinkを特定のパスにのみ対応させる
Wanoグループ Advent Calendar 2016の11日目の記事になります。11日目の44時くらいです。決して12日目ではない。
AndroidのDeepLink設定のメモ。
https://xxx.com/release/***
https://xxx.com/item/***
のような2つのパスのみにアプリが反応するように以下のように組んでいた。
<activity android:name=".Container.Routing.RoutingActivity"> <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="xxxx.com" /> <data android:pathPrefix="/artist/" /> <data android:pathPrefix="/item/" /> </intent-filter> </activity>
しかしこれでは該当のパス以外のURLにも反応してしまっていた。
そこでリンクを以下のように修正。
... <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="https" android:host="xxxx.com" android:pathPrefix="/artist/" /> </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="https" android:host="xxxx.com" android:pathPrefix="/item/" /> </intent-filter> </activity>
当面はこれで該当のパスにのみDeepLinkが適用されるようになった。