Notification Every Time Wifi Is Disconnected
I need my application to give a notification whenever WiFi goes offline. I got it to give a notification every time the WiFi connection changes. But I need it to only give a notifi
Solution 1:
use this line in onReceive()
of BroadCastReceiver
if(!isNetworkConnectionAvailable(ctx)){
Toast.makeText(ctx, "Network Connection Available ", Toast.LENGTH_LONG).show();
}
the code for isNetworkConnectionAvailable() is
publicstaticbooleanisNetworkConnectionAvailable(Context context)
{
booleanisNetworkConnectionAvailable=false;
ConnectivityManagerconnectivityManager= (ConnectivityManager)context.getSystemService("connectivity");
NetworkInfoactiveNetworkInfo= connectivityManager.getActiveNetworkInfo();
if(activeNetworkInfo != null)
{
isNetworkConnectionAvailable = activeNetworkInfo.getState() == NetworkInfo.State.CONNECTED;
}
return isNetworkConnectionAvailable;
}
comment me about result
Solution 2:
Use this to check connectivity InetAddress.isReachable, the method returns true if you have connectivity else false
Post a Comment for "Notification Every Time Wifi Is Disconnected"