Webview没有加载网页?

时间:2015-01-29 03:37:14

标签: android android-webview

您好我正在创建一个加载网址的应用。 它工作正常,但当我尝试加载vine.co它没有显示任何data.works像loadin .......... 我很困惑我在这里失踪的东西。 见我的代码。 网址网址:http://likesplusmore.com/html/

android代码是:

public class MainActivity extends Activity {

private WebView wv;
private WebView wv1;
//private String url = "http://www.m.morefreefollowers.filebanks.info/html";
private String url = "http://www.likesplusmore.com/html";

private String mUrl;
private String fbUrl;
private CountDownTimer countDownTimer;
private final long startTime = 60 * 1000;
private final long interval = 1 * 1000;
private boolean timerHasStarted = false;
private Button btn_back;
private Button btn_refresh;
private RelativeLayout rlBtn;
private String currentUrl;
private ArrayList<String> domainList;

@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    countDownTimer = new MyCountDownTimer(startTime, interval);
    wv = (WebView) findViewById(R.id.wv_content);
    wv1 = (WebView) findViewById(R.id.wv_content1);
    btn_back = (Button) findViewById(R.id.btn_back);
    btn_refresh = (Button) findViewById(R.id.btn_refresh);
    rlBtn = (RelativeLayout) findViewById(R.id.lnBtn);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setLoadWithOverviewMode(true);
    wv.getSettings().setUseWideViewPort(true);
    wv.getSettings().setBuiltInZoomControls(true);
    wv.getSettings().setPluginState(PluginState.ON);
    wv.getSettings().setSupportMultipleWindows(false);
    wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
    wv.setWebViewClient(new myWebClient());
    wv.loadUrl(url);
    wv1.getSettings().setJavaScriptEnabled(true);
    wv1.getSettings().setLoadWithOverviewMode(true);
    wv1.getSettings().setUseWideViewPort(true);
    wv1.getSettings().setBuiltInZoomControls(true);
    wv1.getSettings().setPluginState(PluginState.ON);
    wv1.getSettings().setSupportMultipleWindows(false);
    wv1.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
    wv1.setWebViewClient(new myWebClient1());
    AddDomainList();
    OnClick();
}
//add more domain
private void AddDomainList() {
    domainList=new ArrayList<String>();
    domainList.add("www.facebook.com");
    domainList.add("www.facebook.vn");
    domainList.add("facebook.com");
    domainList.add("facebook.vn");
    domainList.add("youtube.com");
    domainList.add("www.youtube.com");
    domainList.add("twitter.com");
    domainList.add("www.twitter.com");
    domainList.add("soundcloud.com");
    domainList.add("www.soundcloud.com");
    domainList.add("www.pinterest.com");
    domainList.add("pinterest.com");
    domainList.add("instagram.com");
    domainList.add("www.instagram.com");
    domainList.add("linkedin.com");
    domainList.add("vine.co");
    domainList.add("www.google.com.vn");
    domainList.add("plus.google.com");
    domainList.add("www.vine.co");

}

private boolean ContainDomain(String url)
{
    boolean contain=false;
    for(int i=0;i<domainList.size();i++)
    {
        if(url.contains(domainList.get(i)))
        {
            contain=true;
            break;
        }
    }
    return contain;
}
private void OnClick() {
    btn_back.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            BackEvent();
        }
    });
    btn_refresh.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (wv1.getVisibility() == View.VISIBLE) {
                wv1.loadUrl(currentUrl);
            }

        }
    });
}

public class myWebClient extends WebViewClient {
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // TODO Auto-generated method stub
        super.onPageStarted(view, url, favicon);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (ContainDomain(url)) {
            wv1.setVisibility(View.VISIBLE);
            rlBtn.setVisibility(View.VISIBLE);
            wv1.loadUrl(url);
            if (timerHasStarted == false) {
                countDownTimer.start();
                timerHasStarted = true;
            }
            CallWebApi caller = new CallWebApi();
            //caller.execute("http://m.morefreefollowers.filebanks.info/ws/actionfirstfblike.php?url="+ url);
            caller.execute(url);

            wv.setVisibility(View.GONE);
            wv.loadUrl("about:blank");
            fbUrl = url;
        } else {
            wv1.loadUrl("about:blank");
            wv1.setVisibility(View.GONE);
            rlBtn.setVisibility(View.GONE);
            wv.setVisibility(View.VISIBLE);
            wv.loadUrl(url);
            mUrl = url;
        }
        return true;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url);
    }
}

public class myWebClient1 extends WebViewClient {
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        wv1.loadUrl(url);
        currentUrl = url;
        return true;

    }

    @Override
    public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url);

    }
}

@Override
public void onBackPressed() {
    BackEvent();
}

private void BackEvent() {
    if (wv1.getVisibility() == View.VISIBLE) {
        CallWebApi caller = new CallWebApi();
        //caller.execute("http://m.morefreefollowers.filebanks.info/ws/actionfblike.php?url="+ fbUrl);
        caller.execute(fbUrl);

        wv1.loadUrl("about:blank");
        wv1.setVisibility(View.GONE);
        rlBtn.setVisibility(View.GONE);
        wv.setVisibility(View.VISIBLE);
        wv.loadUrl(mUrl);
        if (timerHasStarted == true) {
            countDownTimer.cancel();
            timerHasStarted = false;
        }

    } else {
        finish();
    }
}

public class CallWebApi extends AsyncTask<String, Void, Void> {

    @Override
    protected Void doInBackground(String... params) {
        String url = params[0];
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(url);
        post.setHeader("Accept-Charset", "utf-8");
        post.setHeader("Accept",
                "text/xml,application/text+xml,application/soap+xml");
        HttpResponse response = null;
        String responseBody = "";
        try {
            response = client.execute(post);
            responseBody = EntityUtils.toString(response.getEntity(),
                    "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (response != null) {
            Log.i("VALUE", responseBody);
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
    }

}

public class MyCountDownTimer extends CountDownTimer {
    public MyCountDownTimer(long startTime, long interval) {
        super(startTime, interval);
    }

    @Override
    public void onFinish() {
        if (wv1.getVisibility() == View.VISIBLE) { 
            if (timerHasStarted == true) {
                countDownTimer.cancel();
                timerHasStarted = false;
            }
            CallWebApi caller = new CallWebApi();
            //caller.execute("http://m.morefreefollowers.filebanks.info/ws/actionfblike.php?url="+ fbUrl);
            caller.execute(fbUrl);
            wv1.loadUrl("about:blank");
            wv1.setVisibility(View.GONE);
            rlBtn.setVisibility(View.GONE);
            wv.setVisibility(View.VISIBLE);
            wv.loadUrl(mUrl);

        } else {
            if (timerHasStarted == true) {
                countDownTimer.cancel();
                timerHasStarted = false;
            }
        }
    }

    @Override
    public void onTick(long millisUntilFinished) {
    }
}

}

我已启用java脚本等,它可以加载所有页面。但在vine.co.中创建问题 任何身体都可以告诉我我错过了什么。在网站上工作正常。 谢谢

1 个答案:

答案 0 :(得分:0)

vine.co是https协议。

请在Google搜索&#34; webview https&#34;

将此覆盖方法添加到WebViewClient实现中。您需要使用Android SDK 2.2(API级别8)或更高版本进行编译。该方法从2.2(API级别8)开始出现在公共SDK中,但我们已经在运行2.1,1.6和1.5的设备上对其进行了测试,并且它也可以在这些设备上运行(显然行为一直存在)。

@覆盖

public void onReceivedSslError(WebView视图,SslErrorHandler处理程序,SslError错误){

handler.proceed(); // Ignore SSL certificate errors

}