我正试图在我的应用程序中实现深度链接。
以下是两个urls:
http://www.example.com/games/randomtext-game-randomno : Url1
http://www.example.com/games/randomno-scores/randomscore : Url2
很明显,这两个urls的初始部分解析为相同的模式。在这种情况下,是否有办法区分两种模式,以便每一种模式都分别为需求服务。我已经浏览过各种SO链接并尝试了许多模式,但问题是为url1选择的模式也自动解决了url2问题。游戏和分数在上面的urls中是常量,所以我想用它们来区分。提前谢谢。
发布于 2016-05-25 07:45:00
Url1:http://www.example.com/games/randomtext-game-randomno/
<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" android:host="www.example.com"
android:pathPattern="\\/games\\/.*game.*\\/.*"/>
</intent-filter>Url2:http://www.example.com/games/randomno-scores/randomscore
<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" android:host="www.example.com"
android:pathPattern="\\/games\\/.*scores\\/.*"/>
</intent-filter>发布于 2016-05-31 07:44:50
如果在同一级别(在/games之后)所有链接都不同,那么在解析uri时,您可以这样做:
Uri uri = getIntent().getData();
String category = uri.getPathSegments().get(1);类别将是随机文本-游戏-随机的Url1和随机分数的Url2.
关于getPathSegments() https://developer.android.com/reference/android/net/Uri.html的更多信息
https://stackoverflow.com/questions/37429303
复制相似问题