I am working on online app. [Problem] when internet is down or not available it gives me error [Force close], I tried to handle using broadCast Receiver but not meet exact solut
Just use this function to check whether the Internet connection is available or not:
/**
* Checks if the device has Internet connection.
*
* @return true
if the phone is connected to the Internet.
*/
public static boolean checkNetworkConnection(Context context)
{
final ConnectivityManager connMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
final android.net.NetworkInfo wifi =connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
final android.net.NetworkInfo mobile =connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if(wifi.isAvailable()||mobile.isAvailable())
return true;
else
return false;
}
Don't forget to add permission inside the AndroidManifest.xml file: