environment - Getting all the total and available space on Android -


to knowledge, on android, there is:

  • internal memory apps , cache
  • internal sd card on phones (not removable)
  • external sd card music , photos (removable)

how total , available each check exist (some phones not have internal sd card)

thanks

here how internal storage sizes:

 statfs statfs = new statfs(environment.getrootdirectory().getabsolutepath());          long blocksize = statfs.getblocksize();  long totalsize = statfs.getblockcount()*blocksize;  long availablesize = statfs.getavailableblocks()*blocksize;  long freesize = statfs.getfreeblocks()*blocksize; 

here how external storage sizes (sd card size):

 statfs statfs = new statfs(environment.getexternalstoragedirectory().getabsolutepath());          long blocksize = statfs.getblocksize();  long totalsize = statfs.getblockcount()*blocksize;  long availablesize = statfs.getavailableblocks()*blocksize;  long freesize = statfs.getfreeblocks()*blocksize; 

short note

free blocks:

the total number of blocks free on file system, including reserved blocks (that not available normal applications).

available blocks:

the number of blocks free on file system , available applications.


here how detect whether sd card mounted:

 string state = environment.getexternalstoragestate();  if (environment.media_mounted.equals(state))   {    // can read , write media      }   else if (environment.media_mounted_read_only.equals(state))   {     // can read media       }   else   {     // no external media  } 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -