Thursday, 23 April 2015

Check External SD-Card Available or Not : code snippets

 /*
* Check External SDCARD Is Inserted OR Not
*/

public static boolean isExternalSDCardAvailable(Context c)
{
boolean flagExSdcard = false;
try
{
String exsdcard_path = "/sys/block/mmcblk1";
File file = new File(exsdcard_path);

String memBlk = null;

if (file.exists() && file.isDirectory())
{
flagExSdcard = true;
}

if (flagExSdcard == false)
{
Map<String, File> externalLocations = ExternalStorage
.getAllStorageLocations();
File sdCard = externalLocations.get(ExternalStorage.SD_CARD);
File externalSdCard = externalLocations
.get(ExternalStorage.EXTERNAL_SD_CARD);

if (externalSdCard != null)
{
flagExSdcard = true;
}
}
}
catch (Exception e)
{
e.printStackTrace();
return false;
}

return flagExSdcard;
}

No comments:

Post a Comment