简体   繁体   English

如何通过“使用完成操作”和“共享通过”菜单截取所有链接并定向到我的Android应用程序?

[英]How to intercept all links and direct to my Android app, via both the “complete action using” and “share via” menus?

I'm trying to catch links from apps and direct them to mine. 我正在尝试从应用程序中捕获链接,并将其定向到我的应用程序。 Even though I've implement the details everyone suggested, I just couldn't get it to work. 即使我已经实现了每个人建议的细节,但我还是无法使它起作用。

I have the following intent filter in my AndroidManifest.xml: 我的AndroidManifest.xml中包含以下意图过滤器:

<intent-filter>
            <data android:scheme="http"
              android:host="*"
              android:pathPrefix="*" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <action android:name="android.intent.action.SEND" />
            <data android:mimeType="text/plain" />
            <action android:name="android.intent.action.SENDTO" />
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

I can catch links that are shared, my app gets listed on the "share via" list, but it doesn't get listed on the "complete action using" list. 我可以捕获共享的链接,我的应用程序会列在“共享方式”列表中,但它不会列在“使用完成操作”列表中。

I have also tried adding host and pathPrefix but it didn't work that way either. 我也曾尝试添加host和pathPrefix,但是它也不起作用。

Any suggestions? 有什么建议么? Thank you in advance. 先感谢您。

First, pathPrefix takes a prefix. 首先, pathPrefix带一个前缀。 Hence, your <intent-filter> will only support URLs that begin with an asterisk in their path, which will be few URLs, if any. 因此,您的<intent-filter>仅支持在路径中以星号开头的URL,该URL很少(如果有)。

Second, as OrhanC1 indicated, this should be at least two <intent-filter> elements, one for VIEW and one for SENDTO . 其次,正如OrhanC1所指出的,这应该至少是两个<intent-filter>元素,一个用于VIEW ,一个用于SENDTO In truth, you need three: 实际上,您需要三个:

  1. VIEW + ( BROWSABLE and DEFAULT ) VIEW +( BROWSABLEDEFAULT
  2. ( SEND and SENDTO ) + DEFAULT SENDSENDTO )+ DEFAULT
  3. MAIN + LAUNCHER MAIN + LAUNCHER

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM