Intent-Filterでpathありとpathなしを一瞬で見分ける方法
AndroidManifest.xmlでschemeとhostを指定するとき、
myapp://myhost/mypath
と myapp://myhost
を見分けるのに地味に困りました。
この問題は正規表現で一発解決しました。
「myapp://myhost/mypath」
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="myhost"
android:pathPattern="mypath"
android:scheme="myapp" />
</intent-filter>
「myapp://myhost」
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="myhost"
android:scheme="myapp" />
</intent-filter>
↑ これだとmyapp://myhost/mypath
と myapp://myhost
の両方に反応してしまう。
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="myhost"
android:pathPattern="\s"
android:scheme="myapp" />
</intent-filter>
↑ そこで空文字を表す正規表現の\s
を使うとmyapp://myhost
にしか反応しなくなる。
これでRESTFULなスキーマにも対応できる。
Author And Source
この問題について(Intent-Filterでpathありとpathなしを一瞬で見分ける方法), 我々は、より多くの情報をここで見つけました https://qiita.com/KEN0331/items/155c6770004938df8d51著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .