Open play store app from browser link

43,440

Solution 1

I got it working by using the below url on redirect

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

When I visit this url from the browser of my mobile, it does not open the play store within browser but opens the play store app instead. This serves my purpose.

Solution 2

You can do this by checking URL in shouldOverrideUrlLoading method of your WebViewClient. See below

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>

This will always open your link in play store.

Solution 3

I think a better way to do this could be

    $(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';
 }
});
Share:
43,440

Related videos on Youtube

Hitesh
Author by

Hitesh

Software Developer, System Analyst Life Runs On Code

Updated on April 23, 2022

Comments

  • Hitesh
    Hitesh about 2 years

    From this post I was able to create a functionality to redirect user to android or ios from a single link. However, on detection of Android I want to open the play store with my app shown. I tried the below link on redirect:

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

    but it opens the play store in the browser itself. I want to open the play store app, I am assuming that my app users will be having the play store app, so I do not want to check whether the play store app is installed or not. I also tried the market link as below

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

    but this also does not work. Help appreciated.

    • Iamat8
      Iamat8 about 6 years
      you want to redirect from browser itself ? or from any click event ?
    • Hitesh
      Hitesh about 6 years
      From the browser itself, no click event.
    • Iamat8
      Iamat8 about 6 years
      You are using webviewclient ?
    • Hitesh
      Hitesh about 6 years
      No, I am sharing the link to my users via url.
    • Iamat8
      Iamat8 about 6 years
      have you checked my solution ?
  • Gil Epshtain
    Gil Epshtain over 5 years
    Can you explain why this link is working while the others return "Navigation blocked" error by the Browser. Can you specify a link to any documentation regarding this link.
  • Kazuya  Gosho
    Kazuya Gosho about 5 years
    From Chrome 40, Navigation is blocked: market://details?id=**** is shown.
  • Sobinscott
    Sobinscott almost 5 years
    Is there any similar way to launch appstore app on link click?
  • BuffK
    BuffK about 4 years
    play.app.goo.gl/.well-known/assetlinks.json This is a dynamic link supported by Firebase and Play Service
  • anj28
    anj28 over 3 years
    Hello. When I try to do this - window.location.href = "play.app.goo.gl/?link=https://play.google.com/store/apps/…"‌​; I get an Unsupported URI Scheme. It tries to load the webpage at intent://play.app.goo.... Any idea what I could do to fix it?