I want to find the information regarding internal and external storage capacity of a device programmatically in android . Any Ideas ?
Asked
Active
Viewed 6,213 times
0
-
1refer [here](http://stackoverflow.com/a/5083482/2345913) – CRUSADER Jun 28 '13 at 11:20
1 Answers
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