Android 通过重定向链接在 Google Play 中打开应用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10401247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Opening app in Google Play from a redirect link
提问by nicobatu
On an Android device, opening a link to an app on Google Play:
在 Android 设备上,打开指向 Google Play 应用程序的链接:
https://play.google.com/store/apps/details?id=com.rovio.angrybirds&hl=en
https://play.google.com/store/apps/details?id=com.rovio.angrybirds&hl=en
will automatically open the Google Play app by default.
默认情况下会自动打开 Google Play 应用程序。
But if you have a link that redirects to the Google Play link, the device opens the browser and then navigates to the browser version of Google Play. Why does this behavior occur?
但是,如果您有一个重定向到 Google Play 链接的链接,设备会打开浏览器,然后导航到 Google Play 的浏览器版本。为什么会出现这种行为?
Unfortunately I cannot use the market:// with Intents which can open Play, I have only control over a web link.
不幸的是,我不能将 market:// 与可以打开 Play 的 Intent 一起使用,我只能控制一个网络链接。
edit:Seems like if I have the link redirect to the market:// url, it can open with Google Play on device.
编辑:似乎如果我将链接重定向到市场:// 网址,它可以在设备上使用 Google Play 打开。
If link is opened in browser, somehow it is able to redirect to browser version of Google Play despite market:// not being supported in browser.
如果在浏览器中打开链接,尽管浏览器不支持 market://,但它仍能以某种方式重定向到 Google Play 的浏览器版本。
采纳答案by Booger
Basically, the https://play.... is just a web URL. I suspect the way this works (which is the way standard way Android works) is:
基本上,https://play.... 只是一个网址。我怀疑它的工作方式(这是 Android 的标准工作方式)是:
- The Market Play App registers to be able to handle URLs of this kind (you can register to handle certain intents, and apply filters to further define what your app will handle).
- The app launches the Intent with the https://play... URL
- The User is presented with a list of all apps that are registered to handle that intent. SO, the User is able to launch the Play App - the first time (on the phone) the https:\play... intent is launched
- When the user chooses which app to fulfill the Intent, if they select Browser (then set it as a default) - the Browser will launch (and will not offer the user the option the next time).
- This default can be by: "Settings\Applications\All - Then find the Browser App, select it, and then select Clear Defaults"
- Market Play 应用程序注册为能够处理此类 URL(您可以注册以处理某些意图,并应用过滤器以进一步定义您的应用程序将处理的内容)。
- 该应用程序使用https://play... URL启动 Intent
- 用户将看到所有注册以处理该意图的应用程序的列表。因此,用户可以启动 Play 应用程序 - 第一次(在手机上)https:\play... 意图启动
- 当用户选择哪个应用程序来实现意图时,如果他们选择浏览器(然后将其设置为默认值) - 浏览器将启动(并且下次不会为用户提供该选项)。
- 此默认值可以是:“设置\应用程序\全部 - 然后找到浏览器应用程序,选择它,然后选择清除默认值”
You can either call the Play Market directly with the market intent, or use the URL way. I personally use the URL way - even though there are some additional challenges to use it (like handling this particular issue).
您可以使用市场意图直接调用 Play Market,也可以使用 URL 方式。我个人使用 URL 方式 - 即使使用它还有一些额外的挑战(比如处理这个特定问题)。
回答by Jokry
Use target="_top"
用 target="_top"
<a href="market://details?id={package_name}" target="_top">App</a>
回答by hanspeide
My guess would be that the behaviour is enforced by Google. Redirects would potentially make it easier for developers with bad intentions to install their apps. Google probably checks if the user comes from a redirect, and if yes it doesn't trigger opening of the Play app.
我的猜测是该行为是由 Google 强制执行的。重定向可能会使怀有恶意的开发人员更容易安装他们的应用程序。Google 可能会检查用户是否来自重定向,如果是,则不会触发 Play 应用程序的打开。