How to read the SD Card ID number?

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

    I made this one... it worked for me... hope it makes u clear!

    String getSDCARDiD()
        {
            try {
    
                File file = new File("/sys/block/mmcblk1");
                if (file.exists() && file.isDirectory()) {
    
                    memBlk = "mmcblk1";
                } else {
                    //System.out.println("not a directory");
                    memBlk = "mmcblk0";
                }
    
                Process cmd = Runtime.getRuntime().exec("cat /sys/block/"+memBlk+"/device/cid");
                BufferedReader br = new BufferedReader(new InputStreamReader(cmd.getInputStream()));
                sd_cid = br.readLine();
                //System.out.println(sd_cid);
    
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return sd_cid;
        }
    

提交回复
热议问题