【问题标题】:Open play store app from browser link从浏览器链接打开 Play 商店应用
【发布时间】:2018-12-06 09:26:15
【问题描述】:

从this post 我能够创建一个功能,将用户从单个链接重定向到 android 或 ios。但是,在检测到 Android 时,我想打开显示我的应用的 Play 商店。我在重定向上尝试了以下链接:

window.location.href = "https://play.google.com/store/apps/details?id=com.myapp";

但它会在浏览器本身中打开播放商店。我想打开 Play 商店应用程序,我假设我的应用程序用户将拥有 Play 商店应用程序,所以我不想检查 Play 商店应用程序是否已安装。我也试过市场链接如下

window.location.href = "market://details?id=com.myapp";

但这也行不通。帮助表示赞赏。

【问题讨论】:

  • 你想从浏览器本身重定向?或来自任何点击事件?
  • 从浏览器本身,没有点击事件。
  • 你在使用 webviewclient 吗?
  • 不,我通过 url 将链接分享给我的用户。
  • 你检查过我的解决方案了吗?

标签: android browser google-play


【解决方案1】:

我认为更好的方法是

    $(document).ready(function (){
 if(navigator.userAgent.toLowerCase().indexOf("android") > -1){
     window.location.href = 'http://play.google.com/store/apps/details?id=com.truecaller&hl=en';
 }
 if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){
     window.location.href = 'http://itunes.apple.com/lb/app/truecaller-caller-id-number/id448142450?mt=8';
 }
});

【讨论】:

  • 从 Chrome 40 开始,显示Navigation is blocked: market://details?id=****。
【解决方案2】:

我通过在重定向上使用下面的 url 让它工作

window.location.href = "https://play.app.goo.gl/?link=https://play.google.com/store/apps/details?id=com.myapp";

当我从手机浏览器访问此网址时,它不会在浏览器中打开 Play 商店,而是打开 Play 商店应用程序。这符合我的目的。

【讨论】:

  • 你能解释一下为什么这个链接可以正常工作,而其他链接则返回浏览器“导航被阻止”错误。您能否指定指向有关此链接的任何文档的链接。
  • 是否有类似的方法可以在点击链接时启动 appstore 应用?
  • play.app.goo.gl/.well-known/assetlinks.json 这是 Firebase 和 Play 服务支持的动态链接
  • 你好。当我尝试这样做时 - window.location.href = "play.app.goo.gl/?link=https://play.google.com/store/apps/…";我得到一个不受支持的 URI 方案。它尝试在 intent://play.app.goo 加载网页......知道我能做些什么来修复它吗?
【解决方案3】:

您可以通过在 WebViewClient 的 shouldOverrideUrlLoading 方法中检查 URL 来做到这一点。见下文

String market_url = "market://details?id=package_name";
String website_url = "https://play.google.com/store/apps/details?id=package_name";

onCreate()

WebView webview = (WebView) findViewById(R.id.webview);
webview.loadUrl("file:///android_asset/index.html");               // path to html
webview.setWebViewClient(new Callback());


private class Callback extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.equals(website_url)) {
            try {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(market_url));
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
            }
        }
        return (false);
    }
}

index.html

<a href="https://play.google.com/store/apps/details?id=package_name">App link</a>

这将始终在 Play 商店中打开您的链接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-16
    • 1970-01-01
    相关资源
    最近更新 更多