Hi I am working with android webview application.I uses my the url succesfully in my app and it works only if internet connection available .But I want to show some messages
Use Below code:
boolean internetCheck;
/*
*
* Method to check Internet connection is available
*/
public static boolean isInternetAvailable(Context context) {
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;
boolean connectionavailable = false;
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
NetworkInfo informationabtnet = cm.getActiveNetworkInfo();
for (NetworkInfo ni : netInfo) {
try {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
if (informationabtnet.isAvailable()
&& informationabtnet.isConnected())
connectionavailable = true;
} catch (Exception e) {
// TODO: handle exception
System.out.println("Inside utils catch clause , exception is"
+ e.toString());
e.printStackTrace();
/*
* haveConnectedWifi = false; haveConnectedMobile = false;
* connectionavailable = false;
*/
}
}
return haveConnectedWifi || haveConnectedMobile;
}
It return true if network is available otherwise false In the mantifest add below permissions