启用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 (将#修改为@)