can't open twitter url in android webview

2019-02-25 02:08发布

问题:

I have a problem in my ANDROID application.

I would like to display a twitter page in my webview but the URL won't open.

It keeps loading infinitely.

I am using sdk 1.6.

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadsImagesAutomatically(true);
    webView.setBackgroundColor(0x00000000);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

    final Activity activity = this;
    webView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            activity.setProgress(progress * 100);
            Log.e("progress",progress+" "+((progress * 100)));
            if(progress==100)
            {
                //getWindow().setFeatureInt(Window.FEATURE_PROGRESS,Window.PROGRESS_VISIBILITY_OFF);
                indicator.setVisibility(View.GONE);
            }
            else
            {
                indicator.setVisibility(View.VISIBLE);
            }
        }
    });

    webView.getSettings().setUseWideViewPort(true);
    webView.setWebViewClient(new ApplicationWebViewClient());
}

    private class ApplicationWebViewClient extends WebViewClient { 
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) 
    {
        view.loadUrl(url);
        return super.shouldOverrideUrlLoading(view, url);
    }

回答1:

wv.getSettings().setDomStorageEnabled(true);

This worked for me!



回答2:

I had to set the User Agent String on the webview to get it to work.

wv.getSettings().setUserAgentString("silly_that_i_have_to_do_this");

and that worked for me.

Hope it helps someone else!



回答3:

Your problem is that your shouldOverrideUrlLoading needs to return true to indicate that the host application is managing the load:

private class ApplicationWebViewClient extends WebViewClient { 
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) 
    {
        view.loadUrl(url);
        return true;
    }
}