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なスキーマにも対応できる。