4

In my Android, if I click on on a link that leads to the Play Store, Android automatically opens up the play store so that I can download the app.

If that link is in a webview for the app, instead a webpage opens, similar to the one that would open on a desktop. Is there any way around this? The type of links that I have tried are:

market://details?id=com.alpinereplay.android (doesn't work at all in a webview) https://play.google.com/store/apps/details?id=com.appname.android (opens up a desktop like website)

erdemlal
  • 491
  • 5
  • 21
David
  • 2,834
  • 6
  • 26
  • 31
  • 1
    That's disappointing -- I would have expected `market://` to work. Push come to shove, you could implement your own scheme (e.g., `davidmarket://`) pointing to a `Theme.NoDisplay` activity of yours that turns around and starts up the regular `market://` activity. – CommonsWare Dec 14 '12 at 20:16
  • Yea, that's what we would do, except that the app is already IN the market, so I can't change any of the native code. – David Dec 14 '12 at 21:18

2 Answers2

3

I'm actually quite surprised that this behavior is happening. Are you sure it's not something you're doing explicitly? The docs for shouldOverrideUrlLoading in a WebViewClient say:

by default WebView will ask Activity Manager to choose the proper handler for the url.

If you have a WebViewClient make sure you have code in shouldOverrideUrlLoading to decide when to launch the Play Store vs. load the page in the WebView--perhaps by parsing the URL, getting the scheme, and using the market scheme for your URLs.

kabuko
  • 36,028
  • 10
  • 80
  • 93
0

By default, if you do not set any WebViewClient

webView.loadUrl("market://details?id=your_package");

method doesn't work, it shows page not found. If you try to load a page that contains a market link and if you do not set WebViewClient, this page will be opened in device browser, so you should set a WebViewClient and because you set a WebViewClient; you should handle market links yourself like this answer suggested.

But the following link inside your custom html opens market app even if you do not set a WebViewClient. I think this is the situation mentioned in documentation of shouldOverrideUrlLoading.

String html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><head> </head> <body>  <p><a href=\"market://details?id=your_package\">Market Link</a></p>  </body></html>";
webView.loadDataWithBaseURL("", html, "text/html", "UTF-8", "");
Community
  • 1
  • 1
erdemlal
  • 491
  • 5
  • 21