can't open twitter url in android webview

2019-02-25 01:37发布

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);
    }

3条回答
Fickle 薄情
2楼-- · 2019-02-25 02:01

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;
    }
}
查看更多
叼着烟拽天下
3楼-- · 2019-02-25 02:03

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!

查看更多
倾城 Initia
4楼-- · 2019-02-25 02:23
wv.getSettings().setDomStorageEnabled(true);

This worked for me!

查看更多
登录 后发表回答