Note that there are some explanatory texts on larger screens.

plurals
  1. POGive a notificiation when you disconnect from a specific wifi network
    text
    copied!<p>I need my application to give a notification whenever <strong>a specific</strong> WiFi goes offline.</p> <p>I got it to give a notification every time the WiFi connection disconnects. But I need it to only give a notification when <strong>a specific</strong> WiFi network disconnects. Is my code suitable for this? I read something about class wifiinfo, is this the solution?</p> <p>My question is, how do I alter the code to only give a notification when <strong>a specific</strong> WiFi goes offline? Any help in the right direction would be nice! Some examples would be even more awesome. </p> <p>Thanks in advance!</p> <p>(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.) </p> <p>The code:</p> <pre><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; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload