如何检查 url 是否在 webview 中加载 [英] How to check url is loaded in webview or not
本文介绍了如何检查 url 是否在 webview 中加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码在 android webview 中加载 url
I am loading url in android webview using below code
webviewShowPost.loadUrl(URL);
我想检查是否没有可用的数据连接,然后 webview 而不是显示空白视图,我可以显示没有连接的 Toast.
I want to check if no data connectivity available then webview instead of showing blank view, I can display Toast of no connectivity.
谢谢
推荐答案
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;
}
这篇关于如何检查 url 是否在 webview 中加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文