从 URL 打开应用程序适用于 Android 的 Firefox,但不适用于 Google Chrome
Open App from URL works on Firefox for Android but not on Google Chrome
我想在用户点击 link 到我的网页时打开我的 Android 应用程序(最好从 Facebook 分享 post,但让我们从简单的 URL 开始) .
为此,我创建了一个 Activity 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 头,点击它会转到我的应用程序。这很好。
但是不是在GoogleChrome上工作。当我输入 myapp://test/
时,它会开始 Google 搜索,而当我输入 martinfowler.com
时,它只会打开网页。
我开始在网上研究这个问题并找到了这个文档:https://developer.chrome.com/multidevice/android/intents,说明自定义模式在 Chrome 中不再有效所以我尝试使用这个 URLs (根据文档):
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 搜索。我该怎么做才能从 URL 在 Google Chrome 中打开我的应用程序?
我已经在 KitKat 和 Lolipop 上测试过了。
问题是我一直在键入(或复制)URL到Chrome多功能框(搜索栏),根据这个问题:https://code.google.com/p/chromium/issues/detail?id=451956 不再支持:
In http://crbug.com/331571 we decided not to start an Intent if the
original navigation is started from a user's typing because we thought
that generally a user wouldn't expect to leave Chrome when typing a
URL into the omnibox.
因此,从 URL 在 Google Chrome 中打开应用程序仅在 link 点按时有效,在使用搜索栏时无效。
我想在用户点击 link 到我的网页时打开我的 Android 应用程序(最好从 Facebook 分享 post,但让我们从简单的 URL 开始) .
为此,我创建了一个 Activity 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 头,点击它会转到我的应用程序。这很好。
但是不是在GoogleChrome上工作。当我输入 myapp://test/
时,它会开始 Google 搜索,而当我输入 martinfowler.com
时,它只会打开网页。
我开始在网上研究这个问题并找到了这个文档:https://developer.chrome.com/multidevice/android/intents,说明自定义模式在 Chrome 中不再有效所以我尝试使用这个 URLs (根据文档):
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 搜索。我该怎么做才能从 URL 在 Google Chrome 中打开我的应用程序?
我已经在 KitKat 和 Lolipop 上测试过了。
问题是我一直在键入(或复制)URL到Chrome多功能框(搜索栏),根据这个问题:https://code.google.com/p/chromium/issues/detail?id=451956 不再支持:
In http://crbug.com/331571 we decided not to start an Intent if the original navigation is started from a user's typing because we thought that generally a user wouldn't expect to leave Chrome when typing a URL into the omnibox.
因此,从 URL 在 Google Chrome 中打开应用程序仅在 link 点按时有效,在使用搜索栏时无效。