【问题标题】:Android Respond To URL in IntentAndroid 在 Intent 中响应 URL
【发布时间】:2010-10-06 05:17:09
【问题描述】:

我希望在用户转到某个 url 时启动我的意图:例如,android 市场使用 http://market.android.com/ urls 执行此操作。 youtube也是如此。我也希望我的也这样做。

【问题讨论】:

标签: android url android-intent intentfilter launch


【解决方案1】:

我做到了!使用<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:host="www.youtube.com" android:scheme="http" />
</intent-filter>

这很好用!

【讨论】:

  • 它对我不起作用。您能否提供一个可以打开应用程序的示例链接。
  • 我想回复“www.youtube.com”,但不想回复“www.youtube.com/fr/”...知道我该怎么做吗?
  • 不确定这对整个世界有什么作用。只是在 chrome 上不起作用,它总是在浏览器中打开链接,直到您放置“android:pathPrefix”元素。无论如何,答案没有文档中提到的类别值。如果它仍然对某人不起作用,请参考:stackoverflow.com/a/21727055/2695276 PS:为此挣扎了好几天。
  • 重要的是要知道,这只有在您打开浏览器外部的链接、从笔记应用程序或来自 whatsapp 的消息时才有效,它正在使用棒棒糖
【解决方案2】:

您可能需要在您的意图过滤器中允许不同的数据组合,以使其在不同情况下工作(http/https/www. 与否 www. 等)。

例如,当用户打开指向 Google Drive 表单 (www.docs.google.com/forms) 的链接时,我必须为一个应用程序执行以下操作

注意路径前缀是可选的。

        <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" />
            <data android:scheme="https" />

            <data android:host="www.docs.google.com" />
            <data android:host="docs.google.com" />

            <data android:pathPrefix="/forms" />
        </intent-filter>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-14
    • 1970-01-01
    • 2015-04-09
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多