I have a webview which has this class as webviewclient. This is to make links to pages open in the webview, and links to downloadable files open with the default browser. Here it is:
class LinkWebView extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("/WS/") | url.contains("/Francesco/")
| url.contains("/Gabriele/")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
ClubCiprianisActivity cca = new ClubCiprianisActivity();
cca.comincia(intent);
} catch (Exception ex) {
ClubCiprianisActivity cca = new ClubCiprianisActivity();
cca.tostizza(ex.getMessage());
}
} else {
view.loadUrl(url);
}
return true;
}
}
this webview will load only urls from a specific website so the conditional to choose wheter to open the link in the webview or in the default browser is correct for that website.
ClubCiprianisActivity is the only activity shown in my application, with the webview and all the rest.
method comincia of ClubCiprianisActivity is this:
public void comincia(Intent intent) {
startActivity(intent);
}
I had to make it because Eclipse doesn't recognize the method startActivity in the webviewclient class. tostizza is just showing a Toast because I can't do that either in the webviewclient class. My problem is that when I open al link to a webpage it opens normally, but when I try to open a downloadable link, going into the shouldoverride... I get an error.