3

我正在尝试在 webview 中加载 twitter 小部件文件。我的 webview 加载正确,但是当我尝试打开 webview 中的链接(twitter 小部件文件中的链接)时,我收到上述错误并且整个屏幕变成空白。下面是我正在使用的代码。

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_all);

    String url = getIntent().getExtras().getString("url");

    webProgress = (ProgressBar) mCustomView.findViewById(R.id.webProgress);
    mWebView = (WebView) findViewById(R.id.web_view);
    noDataConnection = (LinearLayout) findViewById(R.id.layout_no_network);
    detector = new ConnectionDetector(this);
    mWebView.getSettings().setDomStorageEnabled(true);

    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // Log.e(TAG, "shouldOverrideUrlLoading : " + url);

            if (!detector.isConnectingToInternet()) {
                noDataConnection.setVisibility(View.VISIBLE);
                webProgress.setVisibility(View.GONE);
                return true;
            } else {
                noDataConnection.setVisibility(View.GONE);
                webProgress.setVisibility(View.VISIBLE);
                return false;
            }
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            noDataConnection.setVisibility(View.VISIBLE);
            webProgress.setVisibility(View.GONE);
        }

    });
    mWebView.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);

            if (newProgress >= 100) {
                Log.e(TAG, "onProgressChanged : 100%");
                webProgress.setVisibility(View.GONE);
            }
        }
    });
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setBuiltInZoomControls(true);
    mWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);


    if (!detector.isConnectingToInternet()) {
        noDataConnection.setVisibility(View.VISIBLE);
        webProgress.setVisibility(View.GONE);
    } else {
        noDataConnection.setVisibility(View.GONE);
        webProgress.setVisibility(View.VISIBLE);
        mWebView.loadUrl(url);
    }
}

任何帮助表示赞赏。

4

1 回答 1

1

我终于找到了这个线程响应的解决方案:

https://stackoverflow.com/a/11280814/555153

正是由于 iFrames,无法很好地检测到推文点击。

于 2014-09-24T14:55:29.337 回答