【问题标题】:launch android app with custom uri使用自定义 uri 启动 android 应用程序
【发布时间】:2013-12-13 15:22:28
【问题描述】:

我尝试通过电子邮件链接启动我的 Android 应用程序。

https://hostname.com/somethingAndParameter

我的服务器将此链接重定向到:

myscheme://host

我尝试了这个意图过滤器,但它不起作用:

<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:host="host" android:scheme="myscheme"/>
</intent-filter>

【问题讨论】:

  • 对我来说看起来不错,尝试删除 BROWSABLE 类别,并看看如果您只在数据过滤器中指定主机 OR 方案,而不是两者都指定会发生什么。您确定 URI 看起来与您期望的完全一样吗?
  • 我试图删除 BROWSABLE 类别,但没有任何改变我的导航器不会拦截链接。而且我需要主机和方案,因为我可以收到启动不同活动的不同链接。示例 myscheme://activity1 启动 activity1 和 myscheme://activity2 启动 activity2。我的电子邮件链接 https:hostname.com/somethingandparameter 启动我的导航器,我的服务器重定向但重定向不起作用。对不起我的英语,谢谢你的帮助:D
  • 对,我想你会需要两者,但我想你可以先让其中一个工作,然后调试问题所在会更容易。也许重定向没有得到正确处理?如果您直接链接到 myscheme://host 而不是重定向怎么办?
  • 相反,为什么不直接设置你的&lt;intent-filter&gt; 来监听https://hostname.com/somethingAndParameter
  • 感谢马特的宝贵时间。我尝试使用:电子邮件链接,但结果是相同的,单独使用方案或同时使用方案和主机。我有一个网页无法访问。

标签: android android-intent android-manifest intentfilter


【解决方案1】:

由于cmets的方式你不理解,我们来试试答案...

将您的 &lt;intent-filter&gt; 更改为:

<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="https"
           android:host="hostname.com"
           android:path="/somethingAndParameter"/>
</intent-filter>

现在您的https://hostname.com/somethingAndParameter URL 可以正常工作了:

  • iOS,因为你说你有这个工作
  • Web,因为你说你有这个工作
  • Android,因为现在当用户在大多数 Android 设备上(通过电子邮件或其他方式)点击此链接时,用户将获得一个选择器,允许用户选择您的应用程序来处理该链接

【讨论】:

  • 感谢您的回答,但它不存在,因为该链接是由服务器生成的,所有链接都存在 host.com/internalandsomeencryptedparameter internal 。我需要了解为什么重定向不被android拦截。
  • @Hugo: "因为链接是由服务器生成的" -- 然后使用android:pathPrefixandroid:pathPattern
  • @CommonsWare感谢您的帮助,但我的 https 链接重定向到 myscheme://host 链接,当我点击我的 https 链接时,android 不会拦截我的 myscheme://host 链接
猜你喜欢
  • 2014-12-08
  • 2011-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-03
  • 2019-01-15
  • 1970-01-01
相关资源
最近更新 更多