Click here to Skip to main content
16,012,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm developing an android media player to play song from memory card.However I need the proper detection of memory cards (removable media). Can I get information about the inserted media - type, manufacturer, etc?
Posted
Comments
Did you research and try anything?

You can use getExternalStorageState[^] .

Quote:
public static String getExternalStorageState (File path)

Added in API level 21
Returns the current state of the storage device that provides the given path.

Returns
one of MEDIA_UNKNOWN, MEDIA_REMOVED, MEDIA_UNMOUNTED, MEDIA_CHECKING, MEDIA_NOFS, MEDIA_MOUNTED, MEDIA_MOUNTED_READ_ONLY, MEDIA_SHARED, MEDIA_BAD_REMOVAL, or MEDIA_UNMOUNTABLE.


public static String getExternalStorageState ()

Added in API level 1
Returns the current state of the primary "external" storage device.

Returns
one of MEDIA_UNKNOWN, MEDIA_REMOVED, MEDIA_UNMOUNTED, MEDIA_CHECKING, MEDIA_NOFS, MEDIA_MOUNTED, MEDIA_MOUNTED_READ_ONLY, MEDIA_SHARED, MEDIA_BAD_REMOVAL, or MEDIA_UNMOUNTABLE.
See Also
getExternalStorageDirectory()
 
Share this answer
 
if (isExteranlStorageAvailable()) {
try {
File input = new File("/sys/class/mmc_host/mmc1");
String cid_directory = null;
int i = 0;
File[] sid = input.listFiles();

for (i = 0; i < sid.length; i++) {
if (sid[i].toString().contains("mmc1:")) {
cid_directory = sid[i].toString();
String SID = (String) sid[i].toString().subSequence(cid_directory.length() - 4,cid_directory.length());
Log.d(TAG, " SID of MMC = " + SID);
break;
}
}
BufferedReader CID = new BufferedReader(new FileReader(cid_directory + "/cid"));
String sd_cid = CID.readLine();
Log.d(TAG, "CID of the MMC = " + sd_cid);
tv.setText("CID of the MMC = " + sd_cid);

} catch (Exception e) {
Log.e("CID_APP", "Can not read SD-card cid");
}

} else {
Toast.makeText(this, "External Storage Not available!!",Toast.LENGTH_SHORT).show();
}

}

private boolean isExteranlStorageAvailable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900