以下のコードを使用してAndroid WebViewにURLをロードしています
webviewShowPost.loadUrl(URL);
空のビューを表示する代わりに、データ接続が利用できないかどうかを確認したい場合は、接続のないトーストを表示できます。
ありがとう
以下のコードを使用してAndroid WebViewにURLをロードしています
webviewShowPost.loadUrl(URL);
空のビューを表示する代わりに、データ接続が利用できないかどうかを確認したい場合は、接続のないトーストを表示できます。
ありがとう
これを試してください
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
super.onReceivedError(view, errorCode, description, failingUrl);
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
});
上記の webview メソッドで進捗率の値を取得できます
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
//Make the bar disappear after URL is loaded, and changes string to Loading...
//Make the bar disappear after URL is loaded
System.out.println("Value of progress"+progress);
pbweb.setProgress(progress);
if(progress == 100)
pbweb.setVisibility(View.GONE);
}
});
以下の進行中のコードは progerss の値です
public static boolean isOnline(Context context) {
try {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo().isConnectedOrConnecting()) {
URL url = new URL("http://www.google.com.pk/");
HttpURLConnection urlc = (HttpURLConnection) url
.openConnection();
urlc.setConnectTimeout(1000); // mTimeout is in seconds
urlc.connect();
if (urlc.getResponseCode() == 200) {
return true;
} else {
return false;
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
この目的のためにいつでも WebViewClient を使用できます。
web.setWebViewClient(new WebViewClient(){
public void onReceivedError(WebView view, int errorCode, String description,String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
ページをロードする前にネットワーク接続があるかどうかを確認したい場合は、これを行う必要があります: https://stackoverflow.com/a/2001824/960048