How to read the SD Card ID number?

后端 未结 12 2112
[愿得一人]
[愿得一人] 2020-12-05 08:15

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?

12条回答
  •  有刺的猬
    2020-12-05 08:47

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

    final StorageManager storageManager = (StorageManager) activity.getSystemService(Context.STORAGE_SERVICE);
    final List 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();
         }
     }
    

提交回复
热议问题