0

I try to execute some code after a link is clicked in a webview. For normal links like http:// I managed this using the shouldOverrideUrlLoading method and view.loadUrl(url);

But with links starting with market:// to redirect to the GooglePlay App, this doesn't work. loadURL("market://") throws a URL not found error.

How can I detect if a market:// link is clicked in a webview ?

My Code:

wvinfo.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

              if (url.startsWith("http")) {
                    view.loadUrl(url);  // WORKS
                    return true;
              } else if (url.startsWith("market:")){
        <DO SOMETHING SPECIAL>
                  view.loadUrl(url); // DOESN'T WORK
                  return true;
              }
        }

});
Berti
  • 91
  • 5
mcfly soft
  • 11,289
  • 26
  • 98
  • 202

2 Answers2

1

Your problem is the view.loadUrl. This will always load the URL in a WebView, but you should open the Link directly in the PlayStore like here

Community
  • 1
  • 1
Berti
  • 91
  • 5
0

You already detect if a market:// link is clicked, your code is right.

Your question is how to call the GooglePlay App? Use Intent instead of loadUrl:

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setData(Uri.parse(url)); 

startActivity(intent);
Nicolai W.
  • 24
  • 4