android - 单击链接时 Android 上的 Chrome 不触发 Intent 的解决方法

标签 android google-chrome

我正在开发一个 Android 应用程序来处理某些 http(s) 链接的 Intent 。它在大多数情况下都有效,但由于 this bug/missing feature 而不适用于 Chrome 中的链接点击。 .简而言之,Chrome 不会广播这些点击的 Intent 。 :/

这可能最终会得到解决,但与此同时,有人知道解决方法吗?

如果我自己控制链接,我可以使用我自己的 HTTP 方案,例如myapp://...,或者我可以 use JavaScript to fake a button click ,两者都发送 Intent ...但我不控制链接。

具体来说,我想处理像 http://github.com/snarfed 这样的链接.我在 AndroidManifest.xml 中的 Activity 定义如下。它正确地接收来自其他应用的此类链接点击的 Intent 广播,而不是来自 Chrome。

<activity android:name="MyApp" android:exported="true">
  <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="github.com" />
  </intent-filter>
</activity>

最佳答案

您需要在每个数据点中包含方案、主机和路径前缀。

适当 list 的示例:

<activity
    android:name=".PhotostreamActivity"
    android:label="@string/application_name">

    <!-- ... -->            

    <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="flickr.com"
              android:pathPrefix="/photos/" />
        <data android:scheme="http"
              android:host="www.flickr.com"
              android:pathPrefix="/photos/" />
    </intent-filter>
</activity>

此示例取自 Romain Guy 放在一起并在此处的重复问题中引用的应用程序:

Intercepting links from the browser to open my Android app

需要注意的几个注意事项,似乎您需要在 Intent 映射生效之前在后台终止 Chrome,并且如果您直接键入 url,应用程序将不允许使用它,只有当它是一个链接时Chrome 是否提供应用程序的操作。

关于android - 单击链接时 Android 上的 Chrome 不触发 Intent 的解决方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17706667/

相关文章:

android - 显示 map 时应用程序强制关闭

android - Xamarin、C#、Google map fragment 不响应任何命令。 (即移动相机)

android - 计算速度

php - JSON 预览在 Chrome 开发工具中不起作用

google-chrome - 强制 Chrome 跟随 URL 而不是搜索

javascript - 将选项卡关闭到左侧,同时排除固定选项卡

javascript - 仅在 Chrome 中 kendo ui 图的 categoryAxis 标签排序错误

android - 用 FragmentActivity 替换已弃用的 TabActivity

java - 请帮助我的应用程序在我的手机和模拟器上不断崩溃

android - 防止在 Android 上的 Chrome 中滚动 body 不起作用并生成错误消息