【问题标题】:More precise URI scheme更精确的 URI 方案
【发布时间】:2016-12-02 10:09:09
【问题描述】:

问题

我有多种方案可以将用户引导至应用程序的不同部分。问题是,由于所有这些方案都以相同的方式开始,因此用户必须从 Android 应用程序选择器中选择他想去的地方(或者调用带有应用程序的底部框)。 我希望我的方案更“精确”,以避免强迫用户做出这个决定。

代码

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

【问题讨论】:

    标签: android uri-scheme


    【解决方案1】:

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

    有几个选项:-

    1. 使用意图过滤器创建一个中间 DeepLinkActivity 以捕获基本方案/主机/路径前缀,并使用它手动处理 url 并转发到相关 Activity。如果您将来有复杂的 url 结构,这将提供更大的灵活性。

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

    我会推荐选项 1

    【讨论】:

    • 我使用了选项 1,因为它看起来更干净、更通用。感谢您的帮助!
    猜你喜欢
    • 2021-04-30
    • 2012-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-18
    • 1970-01-01
    相关资源
    最近更新 更多