I am new to Android development and running into a bizarre issue for which I cannot find a solution.
I need to determine the total and available space in the filesystem. For this I am trying to use getTotalSpace() and getUsableSpace in java.io.File:
File r = new File(root);
return r.getUsableSpace();
However, I get an error “The method getUsableSpace() is undefined for the type File”
I am not sure what the problem is. Android documentation (http://developer.android.com/reference/java/io/File.html) says that File class supports these methods.
My installation seems to be OK too. I am building for Android 2.2 API 8 using Eclipse 3.6.2 with Android ADT 16.0.0.
Do you know what the issue may be?
Is there an alternative way to determine the file system size on Android without File.getUsableSpace() and File.getTotalSpace()?
Thanks.
getUsableSpace() requires API level 9 or higher.. That’s the reason for the error.
For alternate way, checkout this link
http://developer.android.com/reference/android/os/StatFs.html
It speaks about various methods in StatFs class. You ‘d have to multiply the block size with the number of blocks.
Hope this helps..