我有这个code,但不是因为它的工作原理,它不断开放的WebView什么,我想要的是链接不属于我的网站在默认浏览器打开。任何想法?谢谢
私有类CustomWebViewClient扩展WebViewClient {
@覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
如果(url.contains(message2space.es.vu)){
view.loadUrl(URL);
返回true;
}其他{
返回super.shouldOverrideUrlLoading(查看,网址);
}
}
}
解决方案
现在的问题是,你需要发送的意图到默认的Web浏览器打开链接。你在做什么只是调用你的web视图处理的链接不同的方法。每当你想另一个应用程序来处理的东西你需要使用意图。试试这个code来代替。
私有类CustomWebViewClient扩展WebViewClient {
@覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
如果(url.contains(message2space.es.vu)){
view.loadUrl(URL);
} 其他 {
意图I =新的意图(Intent.ACTION_VIEW,Uri.parse(URL));
startActivity(ⅰ);
}
返回true;
}
}
I have this code, but not because it works, it keeps opening in webview and what I want is that the links do not belong to my website open in your default browser. Any idea? thanks
private class CustomWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.contains("message2space.es.vu")){
view.loadUrl(url);
return true;
}else{
return super.shouldOverrideUrlLoading(view, url);
}
}
}
解决方案
The problem is you need to send an Intent to the default web browser to open the link. What you are doing is just calling a different method in your Webview to handle the link. Whenever you want another app to handle something you need to use Intents. Try this code instead.
private class CustomWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.contains("message2space.es.vu")) {
view.loadUrl(url);
} else {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
}
return true;
}
}
上一篇:使用的setSelected上一个TextView一个的listItem内的ListView内TextView、setSelected、ListView、listItem
下一篇:致命的信号11(SIGSEGV)为00000000(code = 1),螺纹32140螺纹、信号、SIGSEGV、code