【发布时间】:2015-06-14 15:33:59
【问题描述】:
我想在用户点击我的网页链接时打开我的 Android 应用程序(最好来自 Facebook 分享帖子,但让我们从纯 URL 开始)。
为此,我创建了一个活动UrlReceiver 并将此代码添加到我的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>
这在 Firefox for Android 上有效,当我输入 myapp://test/ 时,它会自动打开我的应用程序,当我输入 martinfowler.com 时,URL 旁边有一个 Android 头像,可以点击到我的应用程序。这很好。
但它不能在 Google Chrome 上运行。当我输入 myapp://test/ 时,它会启动 Google 搜索,当我输入 martinfowler.com 时,它只会打开网页。
我开始在网上对此进行挖掘,并找到了这个文档: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 搜索。我该怎么做才能从 Google Chrome 中的 URL 打开我的应用程序?
我已经在 KitKat 和 Lolipop 上对此进行了测试。
【问题讨论】:
标签: android google-chrome firefox intentfilter