有的網頁打得開,有的網頁打不開。打得開的網頁點不開超鏈接,這是怎么回事啊,求大神解答
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
2017-03-15
http://youthlin.com/2014601.html
具體我不清楚,估計跟上面這個情況差不多,參考一下