2

In all versions, i am able to get SdCard details like serial no., CID number .. except Nougot version.

I am using the below methods to get the SdCard details. Both are working fine all versions except Nougat. Those paths are returning null in nougat version

public void getCID() {

    File input = new File("/sys/class/mmc_host/mmc1");
    String cidDirectory = null;

    File[] sid = input.listFiles();

    for (int i = 0; i < sid.length; i++) {
        if (sid[i].toString().contains("mmc1:")) {
            cidDirectory = sid[i].toString();
            String SID = (String) sid[i].toString().subSequence(cidDirectory.length() - 4, cidDirectory.length());
        }
    }

    try {
        BufferedReader CID = new BufferedReader(new FileReader(cidDirectory + "/cid"));


    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

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();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return sd_cid;
}
  • Why it is giving null i didn't understand.
  • Thanks in advance
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • https://stackoverflow.com/a/43640035/2164477, check this answer – Amitabh Sarkar May 11 '18 at 11:13
  • Thanks for such a quick reply, sorry for the late comment @Amitabh, The link you provided in that i didn't find the exact solution, that's more about issue tracker and storageVolume that i checked it's returning null. – Surendra Naidu Karna May 16 '18 at 11:16

1 Answers1

0

Above 7.0 we have to use StorageVolume.getUuid() on StorageVolume which you get from StorageManager.

Ramkumar.M
  • 681
  • 6
  • 21