Help us understand the problem. What is going on with this article?

Intent-Filterでpathありとpathなしを一瞬で見分ける方法

More than 3 years have passed since last update.

AndroidManifest.xmlでschemeとhostを指定するとき、
myapp://myhost/mypathmyapp://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/mypathmyapp://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なスキーマにも対応できる。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away