How to read the SD Card ID number?

后端 未结 12 2221
[愿得一人]
[愿得一人] 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:34

    There is api in android for getting sd card serial id. The method is called getFatVolumeId(String mountPoint), where "mountPoint" is sd card name (you can get this name by calling Environment.getExternalStorageDirectory()). But getFatVolumeId is kindof hidden function (or forgotten), so you want to create package in your project named android.os and the class in it to reference the native method, to be able to call it:

    package android.os;
    
    public class FileUtils {
        public static native int getFatVolumeId(String mountPoint);
    }
    

    And the code is:

    File SdCard = Environment.getExternalStorageDirectory();
    int Serial = FileUtils.getFatVolumeId(SdCard.getName());
    

    Also see the links

    http://groups.google.com/group/android-framework/browse_thread/thread/1abd18435ba20a67?pli=1 http://markmail.org/message/rdl4bhwywywhhiau#query:+page:1+mid:rdl4bhwywywhhiau+state:results

提交回复
热议问题