1

I'm looking to get the android system size programmatically (In fact, my intention is to find the entire storage of the device. But the functions that returns the phone's memory ignore the occupied memory of the Android system):

enter image description here

Faz
  • 322
  • 2
  • 14

1 Answers1

0

You can get internal total memory size this way:

double totalSize = new File(getApplicationContext().getFilesDir().getAbsoluteFile().toString()).getTotalSpace();
double totMb = totalSize / (1024 * 1024);

And you can get internal free size this way:

double availableSize = new File(getApplicationContext().getFilesDir().getAbsoluteFile().toString()).getFreeSpace();
    double freeMb = availableSize/ (1024 * 1024);

Also the code to get external free and total memory size:

long freeBytesExternal =  new File(getExternalFilesDir(null).toString()).getFreeSpace();
       int free = (int) (freeBytesExternal/ (1024 * 1024));
        long totalSize =  new File(getExternalFilesDir(null).toString()).getTotalSpace();
        int total= (int) (totalSize/ (1024 * 1024));
       String availableMb = free+"Mb out of "+total+"MB";

The sum of this sizes is the total available system size!

Ali
  • 87
  • 8
  • getTotalSpace does not returns the real device storage ( ignore the occupied memory of the Android system) – Faz Aug 09 '20 at 07:14
  • @MohammadFazel Try using this method: double availableSize = new File(Environment.getRootDirectory().toString()).getFreeSpace(); – Ali Aug 09 '20 at 07:24
  • Thanks but i'm not looking to get device free space... – Faz Aug 09 '20 at 07:57
  • @MohammadFazel simply replace free with total!: `double availableSize = new File(Environment.getRootDirectory().toString()).getTotalSpace();` – Ali Aug 09 '20 at 09:13
  • As I've said above : getTotalSpace does not returns the real device storage ( ignore the occupied memory of the Android system) – Faz Aug 09 '20 at 09:30