0

I have an android app, there is an activity with a webView, it acts like a browser (it open some links I provided). Whenever I browse through my webView if there is a link that leads to play store to download an app my webView can't respond, it says 'webpage not available'. It can't send an intent to open play store or something like google chrome. How can I do it?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Argus Waikhom
  • 186
  • 6
  • 14

1 Answers1

3

This works for me and opens play store app if it is installed and else shows playstore link within the same webView.

webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (Uri.parse(url).getScheme().equals("market")) {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            Activity host = (Activity) view.getContext();
            host.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
            Uri uri = Uri.parse(url);
            view.loadUrl("http://play.google.com/store/apps/" + uri.getHost() + "?" + uri.getQuery());
            return false;
        }

    }
    return false;
}
});
Anubhav Gupta
  • 2,492
  • 14
  • 27