更精确的URI方案

时间:2016-12-02 10:09:10

标签: android uri-scheme

问题

我有多个方案可以引导用户使用不同的应用程序。问题是,由于所有这些方案都是相同的,因此用户必须从Android应用程序选择器中选择他想去的地方(或者调用带有aplications的底部框)。 我希望我的计划能更精确,更准确。为了避免强迫用户做出这个决定。

CODE

Activity1方案触发器

 <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>

Activity2方案触发器

<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>

我的UriSchemes

foobar://foobar.com/path

http://foobar.com/path

foobar://foobar.com/path/category

http://foobar.com/path/category

1 个答案:

答案 0 :(得分:1)

由于activity1的pathPrefix是Activity1中相同的前缀,因此存在歧义 - 因此android无法明确地解析对activty1的请求。

有几种选择: -

  1. 使用intent过滤器创建一个中间DeepLinkActivity以捕获基本方案/ host / pathPrefix,并使用它来手动处理URL并转发到相关活动。如果您将来有复杂的网址结构,这将提供更大的灵活性。

  2. 将activity2的url更改为唯一的(如果可能的话)

  3. 我建议选项1