目前,我的应用程序中有深度链接集成
<activity android:name="org.yccheok.jstock.gui.news.NewsListFragmentActivity"
android:theme="@style/Theme.JStock.Toolbar.Transparent.Light"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<!-- Sets the intent action to view the activity -->
<action android:name="android.intent.action.VIEW" />
<!-- Allows the link to be opened from a web browser -->
<category android:name="android.intent.category.BROWSABLE" />
<!-- Allows the deep link to be used without specifying the app name -->
<category android:name="android.intent.category.DEFAULT" />
<!-- Accepts URIs that begin with "http://jstock.co/a/news” -->
<data android:scheme="http"
android:host="jstock.co"
android:pathPrefix="/a/news" />
</intent-filter>
</activity>
当用户点击接收到的具有以下格式的链接时
http://jstock.co/a/news?code=XOM&symbol=Exxon+Mobil+Corpo
假设这是一个安装了应用程序的用户。将显示以下屏幕
如果用户选择原生应用 JStock,原生应用将启动,他将获得有用的信息。
但是,如果用户选择 chrome 并单击JUST ONCE,它就没什么用了。更糟糕的是,如果用户选择 chrome 并点击ALWAYS,原生应用将永远没有机会通过深层链接启动。
我想知道,有什么好的方法可以避免这样的问题?我们如何确保深层链接始终打开我们自己的 native 应用程序而不是打开 chrome 浏览器?
感谢@CommonsWare。我已将 AndroidManifest.xml 更改为
<activity android:name="org.yccheok.jstock.gui.news.NewsListFragmentActivity"
android:theme="@style/Theme.JStock.Toolbar.Transparent.Light"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter android:autoVerify="true">
<!-- Sets the intent action to view the activity -->
<action android:name="android.intent.action.VIEW" />
<!-- Allows the link to be opened from a web browser -->
<category android:name="android.intent.category.BROWSABLE" />
<!-- Allows the deep link to be used without specifying the app name -->
<category android:name="android.intent.category.DEFAULT" />
<!-- Accepts URIs that begin with "http://jstock.co/a/news” -->
<data android:scheme="http"
android:host="jstock.co"
android:pathPrefix="/a/news" />
<!-- Accepts URIs that begin with "https://jstock.co/a/news” -->
<data android:scheme="https"
android:host="jstock.co"
android:pathPrefix="/a/news" />
</intent-filter>
</activity>
我还确保 https://jstock.co/.well-known/assetlinks.json可通过以下内容访问。
[{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "org.yccheok.jstock.gui",
"sha256_cert_fingerprints":
["F4:6B:DF:4F:21:74:72:2F:88:E0:4C:09:2A:0C:00:C8:9A:16:D0:C6:DB:9C:BC:46:17:93:52:F4:35:AE:DB:98"]
}
}]
仍然,点击 http://jstock.co/a/news?code=XOM&symbol=Exxon+Mobil+Corpo ,仍然让用户选择 Chrome。
我使用 Android 6 进行了测试,APK 是使用已发布的 key 编译的。
有什么我遗漏的吗?
最佳答案
设置assetlinks.json
文件并要求验证,根据 the documentation .在 Android 6.0+ 上,如果您的 assetlinks.json
可以找到并验证,您的应用程序将用于由您的 <intent-filter>
处理的 URL .
关于android - 我们如何确保深层链接始终打开我们自己的 native 应用程序而不是打开 chrome 浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43441776/