我想在用户点击我的网页链接(最好是来自 Facebook 共享帖子,但让我们从纯 URL 开始)时打开我的 Android 应用程序。
为了实现这一目标,我创建了一个 ActivityUrlReceiver
并将此代码添加到我的AndroidManifest.xml
文件(URL 仅用于测试目的):
<activity
android:name=".main.core.UrlReceiver"
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:host="martinfowler.com"
android:pathPrefix="/"
android:scheme="http"/>
<data
android:host="www.martinfowler.com"
android:pathPrefix="/"
android:scheme="http"/>
<data
android:host="test"
android:scheme="myapp"/>
</intent-filter>
</activity>
这正在努力安卓版火狐浏览器,当我进入myapp://test/
当我输入时,它会自动打开我的应用程序martinfowler.com
网址旁边有一个 Android 头,点击即可进入我的应用程序。这很好。
但它是not致力于谷歌浏览器。当我进入myapp://test/
它开始谷歌搜索,当我输入martinfowler.com
它只是打开网页。
我开始在网上挖掘这个问题并找到了这个文档:https://developer.chrome.com/multidevice/android/intents https://developer.chrome.com/multidevice/android/intents,解释说自定义模式不再在 Chrome 中工作,所以我尝试使用这个 URL(根据文档):
intent://test/#Intent;scheme=myapp;package=com.my.app;end
intent://#Intent;scheme=myapp;package=com.my.app;end
intent://test/#Intent;package=com.my.app;scheme=myapp;end
intent://#Intent;package=com.my.app;scheme=myapp;end
但这些也正在启动谷歌搜索。我该怎么做才能从 Google Chrome 中的 URL 打开我的应用程序?
我已经在 KitKat 和 Lollipop 上进行了测试。