Saturday 30 March 2013

How to check SD card availability in android devices.



The following method returns true if your device is mounted with the SD card else returns false:


      public static boolean isSdCardPresent() {
return android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED);
}


How to check internet connection in android

The below method helps you to find out whether your device is connected with any kind of network :

public boolean isOnline(Context context) {

ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}

  The above function returns true if the device has been connected with the internet else return false.