2016-12-02 54 views
1

问题更精确的URI方案

我有一个引导用户到应用程序的不同部分的多个方案。问题在于,由于所有这些方案的启动都是相同的,所以用户必须选择他想从Android应用程序选择器中去的地方(或者是带有应用程序的底部框被称为)。 我希望我的计划更“精确”,避免强迫用户作出此决定。

CODE

活性1方案触发

<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="foobar.com" android:pathPrefix="/path/category"/> 
    <data android:scheme="foobar" android:host="foobar.com" android:pathPrefix="/path/category"/> 
</intent-filter> 

活性2方案触发

<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="foobar.com" android:pathPrefix="/path"/> 
     <data android:scheme="foobar" android:host="foobar.com" android:pathPrefix="/path"/> 
</intent-filter> 

MY UriSchemes

foobar://foobar.com/path

http://foobar.com/path

foobar://foobar.com/path/category

http://foobar.com/path/category

回答

1

因为活动1的pathPrefix是活动1相同的前缀,那么有歧义存在 - 因此Android不会能明确解决activty1的请求。

有几个选项: -

  1. 请与意图过滤器中间DeepLinkActivity捕捉基本方案/主机/ pathPrefix并用它来手动处理的URL,并转发给相关的活动。如果您将来有更复杂的网址结构,这会提供更大的灵活性。

  2. 更改活性2的网址是一些独特的(如果多数民众赞成可能)

我建议选择1

+0

我使用选项1,因为它看起来更清洁,更versitile。感谢帮助! – JakubW