0

I found someone who asked about enable/disable internet connection and someone else who teaches how to build a notification. So i mixed them up and did this:

 public void sendNotification() {

    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    if (wifi.isWifiEnabled()) {
    } else {

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_notification)
                        .setContentTitle("TURN ON WIFI!!")
                        .setContentText("You should turn it back on!");


        NotificationManager mNotificationManager =

                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    }

}

But it isn't working =(

Community
  • 1
  • 1
Mazal
  • 101
  • 1
  • 9

1 Answers1

0

You need to have a broadcast receiver which listens to SUPPLICANT_CONNECTION_CHANGE_ACTION. Look it up here it has already been achieved.

How to detect when WIFI Connection has been established in Android?

Community
  • 1
  • 1
Pavan
  • 767
  • 4
  • 18