0

I want to find the information regarding internal and external storage capacity of a device programmatically in android . Any Ideas ?

Hammad Shahid
  • 2,216
  • 5
  • 32
  • 60

1 Answers1

4

You need to use the environment variable. Environment.getExternalStorageDirectory(); . There many methods in Environment.java . It depends on what information you need . For example to get external storage name you use Environment.getExternalStorageDirectory().getName(); there are other methods you can make use of them. For Internal storage the api's may not be available publicly .

StatFs stat = new StatFs(type.getPath());
long bytesAvailable = (long)stat.getBlockSize()*(long)stat.getAvailableBlocks();  
long megAvailable = bytesAvailable / (1024 * 1024);  
Log.i("TAG","Available size in MB : "+megAvailable); 

Now we can use getAvailableBytes() api instead of using getBlockSize which is deprecated in API level 18.

where type is File object which might be of type Environment.getExternalStorageDirectory()

Rahul Patil
  • 2,707
  • 2
  • 21
  • 32