How to read the SD Card ID number?

Viewed 48679

How can I programatically read the SD Card's CID register, which contains a Serial Number and other information? Can I do it through Android Java, or Native code?

Thanks in advance, Eric

12 Answers

You can get it with the StorageManager.
Here is a sample-code:

final StorageManager storageManager = (StorageManager) activity.getSystemService(Context.STORAGE_SERVICE);
final List<StorageVolume> storageVolumes = storageManager.getStorageVolumes();
final UserHandle user = android.os.Process.myUserHandle();
for (StorageVolume storageVolume : storageVolumes) {
     // "SDCARD" must be your sd-card name
     if (storageVolume.getDescription(activity).equals("SDCARD")){
        // the SD Card ID number
        return storageVolume.getUuid();
     }
 }
Related