有的网页打得开,有的网页打不开。打得开的网页点不开超链接,这是怎么回事啊,求大神解答
import android.content.Intent;
import android.net.Uri;
import android.support.v4.view.KeyEventCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity{
private String url = "http://www.baidu.com/";
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Uri uri = Uri.parse(url);
//Intent intent = new Intent(Intent.ACTION_VIEW,uri);
//startActivity(intent);
init();
}
private void init(){
webView = (WebView)findViewById(R.id.web_view);
webView.loadUrl(url);
webView.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(url);
return true;
}
});
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);//设置js可以直接打开窗口,如window.open(),默认为false
webSettings.setJavaScriptEnabled(true);//是否允许执行js,默认为false。设置true时,会提醒可能造成XSS漏洞
webSettings.setSupportZoom(true);//是否可以缩放,默认true
webSettings.setBuiltInZoomControls(true);//是否显示缩放按钮,默认false
webSettings.setUseWideViewPort(true);//设置此属性,可任意比例缩放。大视图模式
webSettings.setLoadWithOverviewMode(true);//和setUseWideViewPort(true)一起解决网页自适应问题
webSettings.setAppCacheEnabled(true);//是否使用缓存
webSettings.setDomStorageEnabled(true);//DOM Storage
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_BACK){
if(webView.canGoBack()){
webView.goBack();
return true;
}
else{
System.exit(0);
}
}
return super.onKeyDown(keyCode, event);
}
}
//百度打不开,网页提示ERR_EMPTY_RESPONSE,logcat提示W/cr_BindingManager: Cannot
//call determinedVisibility() - never saw a connection for the pid: 19146