mejkan mejkan - 5 months ago 21
Android Question

sub links of webview are not open on all devices?

i am receiving json string and show in Android webview using

webview.loadData(content, "text/html; charset=UTF-8", null);
json string content showing fine and its links is working correctly on my device(4.1.2)but same links not open on other some devices i tried on other which version is(4.2.2) what i am missing here?

final ProgressDialog progressDialog = new ProgressDialog(Webview_news.this);

WebView webview= (WebView) findViewById(R.id.wv_news);
webview.getSettings().setDomStorageEnabled(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
//webview.getSettings().setPluginState(true);
webview.getSettings().setSupportMultipleWindows(true);
webview.getSettings().setSupportZoom(true);
webview.setVerticalScrollBarEnabled(false);
webview.setHorizontalScrollBarEnabled(true);


webview.loadData(content, "text/html; charset=UTF-8", null);
//Toast.makeText(Webview_news.this, "content= "+content, Toast.LENGTH_LONG).show();




webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}

@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressDialog.dismiss();
}



});

Answer

you should use

     final ProgressDialog progressDialog = new ProgressDialog(Webview_news.this);

            WebView webview= (WebView) findViewById(R.id.wv_news);

            webview.loadData(content, "text/html", "UTF-8");
            webview.setWebChromeClient(new WebChromeClient() {
                                 @Override
                                 public void onProgressChanged(WebView view, int progress) {
                                     if (progress == 100) {
                                        progressDialog.dismiss();                                    }
                                 }
                             });