Joe*_*lio 8 android intentfilter chrome-custom-tabs
我的应用程序打开了一个 customtabs 浏览器,当浏览器遇到某个 url 时,我想弹出来打开我的应用程序。
我发现这篇文章有效 - Android - 为我的应用程序创建一个架构,该架构将使用名为“myapp”的协议从网页链接打开
我更喜欢使用 http/https 协议来触发我的应用程序,但由于某种原因它似乎不起作用。
具体来说,这是有效的:
<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="myapp" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
当浏览器重定向到“myapp://10.2.2.0:3001/cats”时,我的应用程序重新打开,是的!
问题是当我尝试这个(或我尝试过的其他 100 件事中的任何一件)
<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="10.0.2.2" />
<data android:scheme="http" android:host="10.0.2.2" />
<data android:pathPrefix="/cats" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
当我的应用程序重定向到“ http://10.2.2.0:3001/cats ”时它不起作用,作为一个负面影响,它还会问我在打开 customTabs 时我想做什么(使用谷歌浏览器,使用不同的app),无论我选择什么,意图过滤器都不会被触发。
使用 http/https 意图过滤器是否有限制?我究竟做错了什么?
答案来自:从 Android 浏览器启动自定义 Android 应用程序(阅读所有答案,可能有用)
截至 2014 年 1 月 28 日,上述所有答案对我的 Chrome 不起作用
我的应用程序从http://example.com/someresource/链接正确启动,这些链接来自环聊、gmail 等应用程序,但不能从 chrome 浏览器内启动。
要解决这个问题,以便它从 CHROME 正确启动,您必须像这样设置意图过滤器
<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="example.com"
android:pathPrefix="/someresource/"
android:scheme="http" />
<data
android:host="www.example.com"
android:pathPrefix="/someresource/"
android:scheme="http" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
注意 pathPrefix 元素
现在,每当用户通过单击 google 搜索结果或任何其他网站的链接从 chrome 浏览器请求http://example.com/someresource/模式时,您的应用程序就会出现在活动选择器中
更新
我从你的代码中看到的内容应该没有问题。只需尝试在不使用自定义方案的情况下解决您的问题即可。
阅读这个答案:解释为什么不使用自定义方案
另外,如果您有多个操作,请检查将每个操作放入单独的意图过滤器中以及意图过滤器的顺序是否会对您的问题产生任何影响。最后,您尝试过使用意图方案吗?那也值得一试。