Skip to content Skip to sidebar Skip to footer

Get Internal And External Memory Size In Marshmallow

I am trying to show the size of Internal and External(SD card) memory in my application.My code is working fine for kitkat and below api versions but My app is crashing in Marshma

Solution 1:

In lolipop or marshmallo you must use Environment.getExternalStorageDirectory().getAbsolutePath();

to get external storage path instead of System.getenv("SECONDARY_STORAGE");

Refer beolw code for get external and internal storage in >android 5.0

publicstatic String getTotalInternalMemorySize() {
            Filepath= Environment.getDataDirectory();
            StatFsstat=newStatFs(path.getPath());
            longblockSize= stat.getBlockSize();
            longtotalBlocks= stat.getBlockCount();
            return formatSize(totalBlocks * blockSize);
        }

        publicstatic String getAvailableExternalMemorySize() {
                Filepath= Environment.getExternalStorageDirectory();
                StatFsstat=newStatFs(path.getPath());
                longblockSize= stat.getBlockSize();
                longavailableBlocks= stat.getAvailableBlocks();
                return formatSize(availableBlocks * blockSize);
            }   

Post a Comment for "Get Internal And External Memory Size In Marshmallow"