简体   繁体   中英

How to get Android SD card size?

First, I'd like to start by saying, yes I have read and tried just about every single question on this topic posted to SO, so please do not link me to other answers. For example, I have tried something like this , but it returns the same as internal storage. I have about 12GB internal storage and 4GB SD card storage, but no matter what method I use, I always get the exact same number for the SD space as I do for internal space. Are there any other methods to obtaining SD card space?

Well, I ended up writing a bit of code that uses the file /etc/vold.fstab to get all the actual external storage devices. On my TF101 with the docking station attached and populated with storage devices, this will correctly return the path to the 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM