I've a difficult managing open link on webview
content click with Intent.ACTION_VIEW
on different device.
My scenario is: i've some html code displayed within a webview
inside my app, this content have some link (href), then on click event i want to open the link with external app and not inside the same web view.
I've achieved this by:
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(request.getUrl().toString()));
activity.startActivity(intent);
return true;
}
});
So, the problem is that this doesn't happen an all devices.
With Android 7 it's working but on version 6 doesn't. Anyway to manage different version i've already used different implementation.
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
activity.startActivity(intent);
return true;
}
});
I've already look around on stackoverflow but the only answer i've found it's to use the code above.
Thanks for the support
UPDATE - 15/02/18
I've solved the problem, putting the two @Override
method together like this:
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(request.getUrl().toString()));
activity.startActivity(intent);
return true;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
activity.startActivity(intent);
return true;
}
});