Android
7/22/2018 - 12:25 PM

Check Wifi Turn On or Turn Of

You Must Call checkConnection at your Login Or wish Activity


  protected boolean isOnline() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
      return true;
    } else {
      return false;
    }
  }

  public void checkConnection() {
    if (isOnline()) {
    } else {
      AlertDialog.Builder builder = new AlertDialog.Builder(this)
        .setTitle("لطفا اینترنت خود را برسی کنید")
        .setCancelable(false)
        .setNegativeButton("فعلا حال  ندارم", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            return;
          }
        })
        .setPositiveButton("بریم وایفای رو وصل کنیم", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            startActivityForResult(new Intent(Settings.ACTION_WIFI_SETTINGS), 0);
          }
        });

      builder.show();
    }

  }