How to get Android SD card size?

Firstly, I would like to start by saying that: yes, I read and tried almost every question on this topic posted in SO, so please do not connect me with other answers. For example, I tried something like this , but it returns the same as the internal storage. I have about 12 GB of internal memory and 4 GB of SD card memory, but no matter what method I use, I always get the same number for the SD space as for the internal space. Are there any other ways to get SD card space?

+4
source share
1 answer

Well, I ended up writing some code that the file uses /etc/vold.fstabto get all the external storage. On my TF101 with a dock connected and filled with storage devices, this will correctly return the path to microSD, SD and USB drives.

private ArrayList<String> extStorageLoc(){
        String[] toSearch = readFile("/etc/vold.fstab").split(" ");
        ArrayList<String> out = new ArrayList<String>();
        for(int i = 0; i < toSearch.length; i++){
            if(toSearch[i].contains("dev_mount")){
                if(new File(toSearch[i+2]).exists()){
                    out.add(toSearch[i+2]);
                }
            }
        }
        return out;
}
+1
source

Source: https://habr.com/ru/post/1547297/


All Articles