我想在没有连接到互联网时在 webview 应用程序中显示自定义对话框。如何检查互联网连接,然后调用对话框?
最佳答案
您可以使用ConnectivityManager检查是否有互联网连接,您可以显示 Toast AlertDialog给用户的消息。
另请参阅:AlertDialog.Builder
编辑: 以下是如何使用 Toast 消息执行此操作的示例:
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if (info != null) {
if (!info.isConnected()) {
Toast.makeText(this, "Please check your wireless connection and try again.", Toast.LENGTH_SHORT).show();
}
}
else {
Toast.makeText(this, "Please check your wireless connection and try again.", Toast.LENGTH_SHORT).show();
}
关于android - 当没有 Internet 连接时如何显示自定义对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6905262/