Hi guys.I've created a web view app, the page that is displayed features market:// links but upon clicking them I get the 404 screen along with the error that the protocol is not supported. I've tried looking through documentation but was unable to find anything relating to this. Any help is much appreciated.
A:
For the links to work you have to have the market app installed on your device/emulator. Also your app need to request a permission to access network.
UPD: as a workaround you can call java code from within the webview, for example if you generate links like this:
<a href="javascript:go('market://your.path.to.market.app')">..</a>
Define a javascript function named go():
<script type="text/javascript">
function go(link) {
if (handler) {
handler.go(link);
} else {
document.location = link;
}
}
</script>
You then can pass in a handler object into the WebView:
webview.addJavascriptInterface(new Handler() {
@Override
public void go(String marketUrl) {
//start market intent here
}
}, "handler");
Handler interface can be defined as follows:
public interface Handler{
public void go(String url);
}
Konstantin Burov
2010-08-27 10:53:47
I've tried it on the device and it doesn't work. I have network permissions working because everything loads OK but when a market link is clicked I get an error of unsupported protocol. Any help is much appreciated.
2010-08-27 13:14:10
What device do you use? Are you sure that device has market client installed?
Konstantin Burov
2010-08-27 13:39:12
I have the Galaxy S so yep, market fully working on it.
2010-08-27 13:48:15
Or would it be possible to make market:// links open using the default browser instead as a workaround?
2010-08-27 15:13:41
Are the links generated by you? If yes you can use javascript to call android java code, which can start market intent.
Konstantin Burov
2010-08-27 15:47:46
Yeah the links are input by me. It's basically webview wrapping a mobile version of my wordpress site which has market links. So I would use javascript within my website? I'm not familar with javascript so any advice or pointing in the right direction is much appreciated.
2010-08-27 15:56:30
See update to the answer.
Konstantin Burov
2010-08-27 17:00:05
Thanks for the update, I'll give it a go and let you know how it works out :).
2010-08-27 17:08:42
Hmm, another problem I have is that I'm running the admob code from using PHP in the webview, the admob code also links to market links. I could use native android code for admob but that would mean that people who access the site just using the mobile internet wouldnt see ads. Hmmm.
2010-08-27 17:16:33
Then I'd recommend you not to modify the links but rather add onClick handler to each link. At the onClick handler check for existence of 'handler' variable and if that exists, stop the event (to prevent browser action) and call android handler.
Konstantin Burov
2010-08-27 17:21:38
I'm not a big specialist in pure javascript, but I'm pretty sure that what I've described is possible. I think you easily will find lots of examples.
Konstantin Burov
2010-08-27 17:23:36
I'm having some problems figuring out the code - would you be available to hire to do this?
2010-08-28 13:43:26
See updated answer, probably that helps.
Konstantin Burov
2010-08-28 14:34:06