如何解决启用Internet时如何禁用“警报”对话框?
我的代码在Internet处于关闭状态时可以正常工作,而当我在Internet上处于打开状态时,我的甜蜜警报对话框将无法正常工作。
private BroadcastReceiver mNetworkDetectReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context,Intent intent) {
SweetAlertDialog pDialog;
checkInternetConnection();
}
};
public void checkInternetConnection() {
final ConnectivityManager connMgr = (ConnectivityManager)
this.getSystemService(Context.CONNECTIVITY_SERVICE);
final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (wifi.isConnectedOrConnecting ()) {
showNoInternetDialog(false);
Toast.makeText(this,"Connected with Network",Toast.LENGTH_LONG).show();
} else if (mobile.isConnectedOrConnecting ()) {
showNoInternetDialog(false);
Toast.makeText(this,"Connected with Network ",Toast.LENGTH_LONG).show();
} else {
showNoInternetDialog(true);
Toast.makeText(this,"No Network ",Toast.LENGTH_LONG).show();
}
}
private void showNoInternetDialog(Boolean status) {
SweetAlertDialog pDialog = new SweetAlertDialog(this,SweetAlertDialog.ERROR_TYPE);
pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86"));
pDialog.setTitleText("Internet Disabled!");
pDialog.setContentText("No active Internet connection found.");
pDialog.setCancelable(false);
pDialog.show();
pDialog.setConfirmButton("Turn On",new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sweetAlertDialog) {
Intent gpsOptionsIntent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS);
startActivityForResult(gpsOptionsIntent,WIFI_ENABLE_REQUEST);
sweetAlertDialog.dismiss();
}
});
pDialog.setCancelButton("No,Just Exit",new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sweetAlertDialog) {
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
sweetAlertDialog.dismiss();
}
});
if(status) {
pDialog.show();
}
else {
pDialog.cancel();
pDialog.dismiss();
}
}
当Internet处于关闭状态并且同时处于两种情况下时,它都可以正常工作。我可以通过正确的状态打开和关闭Internet,请帮助我,我将不胜感激
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。