How to get exact capacity from storage

☆樱花仙子☆ 提交于 2019-12-07 04:54:36

When I use my code below it shows me a total capacity of 24,4GB.

That is the amount of space on the partition that contains Environment.getExternalStorageDirectory(). There will be other partitions on the device, for which you will not have access.

How to get the exact 32GB total capacity of my device?

There is no means of doing that, except perhaps on a rooted device.

1.First ,open command prompt. Connect your mobile where developer option is on. Write "adb shell" on cmd.You will be now in your phone path. 2.Secondly, write df -h on cmd, which show you the total phone storage is divided into different disk path.

3.See this image.enter image description here

  `  double size =
                    new File("/data").getTotalSpace() / (1024.0 * 1024 * 1024);


            double sizesystem =
                    new File("/system").getTotalSpace() / (1024.0 * 1024 * 1024);

            double sizedev =
                    new File("/dev").getTotalSpace() / (1024.0 * 1024 * 1024);

            double sizecache =
                    new File("/cache").getTotalSpace() / (1024.0 * 1024 * 1024);

            double sizemnt =
                    new File("/mnt").getTotalSpace() / (1024.0 * 1024 * 1024);

            double sizevendor =
                    new File("/vendor").getTotalSpace() / (1024.0 * 1024 * 1024);



            float total = (float) (sizemnt + sizedev + sizesystem + size + sizevendor + sizecache);
            Log.e("total111", String.valueOf(total));`

Here, usE the all dish path and get the size.Then sum up all and get the actual storage of a phone. iF phone is 32 GB, you will see the 32 GB total storage.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!