解决方法为Chrome浏览器在Android上不费一枪意图时,链接被点击 [英] Workaround for Chrome on Android not firing intent when links are clicked

查看:168
本文介绍了解决方法为Chrome浏览器在Android上不费一枪意图时,链接被点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个Android应用程序处理的意图某些HTTP(S)的链接。它的工作原理,在大多数情况下,而不是点击Chrome浏览器链接,由于的这个bug /缺少功能。总之,Chrome不广播意图点击费用。 :/

这可能最终被固定的,但在此期间,没有人知道一个解决办法?

如果我控制了自己的链接,我可以用我自己的HTTP方案,例如:的myapp:// ...,我也可以使用JavaScript假一键点击,这两个派的意图。 ..但我无法控制的环节。

具体来说,我想处理像 http://github.com/snarfed 链接。在的Andr​​oidManifest.xml 我的行为的定义如下。它正确地接收广播的意图对这类链接的点击来自其他应用程序,只是没有从Chrome浏览器。

 <活动机器人:名称=MyApp的机器人:出口=真正的>
  <意向滤光器>
    <作用机器人:名称=android.intent.action.VIEW/>
    <类机器人:名称=android.intent.category.DEFAULT/>
    <类机器人:名称=android.intent.category.BROWSABLE/>
    <数据机器人:计划=HTTP/>
    <数据机器人:计划=HTTPS/>
    <数据机器人:主机=github.com/>
  &所述; /意图滤光器>
< /活性GT;
 

解决方案

您需要包括方案,主机和路径preFIX在每个数据点。

相应清单的例子:

 <活动
    机器人:名称=。PhotostreamActivity
    机器人:标签=@字符串/ APPLICATION_NAME>

    <  - !...  - >

    <意向滤光器>
        <作用机器人:名称=android.intent.action.VIEW/>
        <类机器人:名称=android.intent.category.DEFAULT/>
        <类机器人:名称=android.intent.category.BROWSABLE/>
        <数据机器人:计划=HTTP
              机器人:主机=flickr.com
              机器人:路径preFIX =/照片//>
        <数据机器人:计划=HTTP
              机器人:主机=www.flickr.com
              机器人:路径preFIX =/照片//>
    &所述; /意图滤光器>
< /活性GT;
 

这个例子是从一个应用程序罗曼盖伊放在一起,并引用在这里重复的问题:

<一个href="http://stackoverflow.com/questions/1609573/intercepting-links-from-the-browser-to-open-my-android-app">Intercepting从浏览器链接打开我的Andr​​oid应用程序

夫妇的注意事项要注意的,看来你需要杀死Chrome浏览器在后台的意图映射生效之前,如果你直接输入网址,应用程序将不会被允许使用它,只有当它的一个链接并提供Chrome浏览器的处分直至应用程序。

I'm working on an Android app that handles intents for certain http(s) links. It works in most cases, but not for clicks on links in Chrome, due to this bug/missing feature. In short, Chrome doesn't broadcast an intent for those clicks. :/

That may be fixed eventually, but in the meantime, does anyone know a workaround?

If I controlled the links themselves, I could use my own HTTP scheme, e.g. myapp://..., or I could use JavaScript to fake a button click, both of which send the intent...but I don't control the links.

Specifically, I'd like to handle links like http://github.com/snarfed. My activity's definition in AndroidManifest.xml is below. It correctly receives intent broadcasts for these kinds of link clicks from other apps, just not from 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>

解决方案

You need to include the scheme, host and pathPrefix in each data point.

Example of the appropriate manifest:

<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>

This example is taken from an application Romain Guy put together and referenced in a duplicate question here:

Intercepting links from the browser to open my Android app

Couple of caveats to note, it seems that you need to kill Chrome in the background before the intent mapping takes effect AND if you type the url directly, the application won't be allowed to consume it, only when it's a link does Chrome offer the action up to apps.

这篇关于解决方法为Chrome浏览器在Android上不费一枪意图时,链接被点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆