0

I need my application to give a notification whenever a specific WiFi goes offline.

I got it to give a notification every time the WiFi connection disconnects. But I need it to only give a notification when a specific WiFi network disconnects. Is my code suitable for this? I read something about class wifiinfo, is this the solution?

My question is, how do I alter the code to only give a notification when a specific WiFi goes offline? Any help in the right direction would be nice! Some examples would be even more awesome.

Thanks in advance!

(Eventually I need a button and when you press this the specific wifi your on atm will become that specific wifi when you disconnect from it you get a notification. If that makes sense.)

The code:

protected void onCreate(Bundle savedInstanceState) {        
    // TODO Auto-generated method stub

    super.onCreate(savedInstanceState);  
    this.registerReceiver(this.mConnReceiver,
            new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    setContentView(R.layout.activity_hoofdmenu);        
}

private BroadcastReceiver mConnReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {

        if(!isNetworkConnectionAvailable(context)){
            showNotification();
        }

        }
};

public static boolean isNetworkConnectionAvailable(Context context)
  {
      boolean isNetworkConnectionAvailable = false;

      ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService("connectivity");
      NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();

      if(activeNetworkInfo != null) 
      {
          isNetworkConnectionAvailable = activeNetworkInfo.getState() == NetworkInfo.State.CONNECTED;
      }
      return isNetworkConnectionAvailable;
  }
Kai
  • 38,985
  • 14
  • 88
  • 103
user2883477
  • 153
  • 1
  • 3
  • 16

1 Answers1

0

To detect SSID changes, listen for WifiManager.NETWORK_STATE_CHANGED_ACTION, grab the SSID from the intent extra WifiManager.EXTRA_BSSID.

See: Execute code when wifi SSID changes

Community
  • 1
  • 1
jspurlock
  • 1,466
  • 10
  • 7