【问题标题】:Android intent filter pathpattern for multiple folder levels用于多个文件夹级别的 Android 意图过滤器路径模式
【发布时间】:2016-01-21 14:01:05
【问题描述】:

我有这样的 URI:http://myapp/category/details 和 3 个应该处理此结构不同级别的活动。
活动 1 应处理 http://myapp
活动 2 应处理 http://myapp/category
活动 3 应处理 http://myapp/category/details
我在为数据标签找到正确路径/pathPattern/pathPrefix 的组合时遇到问题。在下面的示例中,所有 3 个活动都乐于处理像 http://myapp/category/details 这样的 uri,并显示“使用完成操作”对话框,其中包含 3 个 myapp 图标。
活动一:

<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="myapp"
</intent-filter> 

活动二:

<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="myapp"
    android:pathPattern="/.*"
</intent-filter>  

活动 3:

<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="myapp"
    android:pathPattern="/.*/.*"
</intent-filter> 

如何防止活动 1 处理用于活动 2 和 3 的链接?
(以及活动 2 处理活动 3 的链接)

【问题讨论】:

    标签: android android-intent intentfilter deep-linking


    【解决方案1】:

    你可以使用mime来区分意图

    <data android...
     android:mimeType: "your specific mime for the intent...can be custom one like activity/activity1
    >
    

    然后使用 mime 运行您的特定 Intent 执行类似操作

    intent.setType("mimeType/mimeSubType");
    if (sendIntent.resolveActivity(getPackageManager()) != null) {
        startActivity(sendIntent);
    }
    

    您也可以(并且应该)使用pathPrefix 来区分路径。

    查看data element 了解更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      • 2011-04-02
      • 1970-01-01
      • 2019-12-12
      • 1970-01-01
      相关资源
      最近更新 更多