如果没有互联网连接,用户点击按钮,它会显示一些使用对话框的错误信息。我在我的android手机webview中尝试navigator.online
。没有工作。如何使用显示消息jquery,或json没有使用java的ajax。
答案 0 :(得分:1)
private boolean checkInternetConnection() {
ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected()) {
return true;
} else {
Toast toast = Toast
.makeText(
getApplicationContext(),
"No Internet Connection Found !!! Please Connect To Internet First",
Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(5000);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
return false;
}
}