0

Is it possible to get the info from Settings -> Storage in android and use it in my app? What I have so far is total space and available space, but I want to get also the space taken by apps, photos, downloads, etc. :

public class MainActivity extends Activity {

private final String TAG = "abc";
private final double BYTES_TO_GB_FACTOR = Math.pow(2, 30);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
    long bytesAvailable = stat.getAvailableBytes();
    long bytesTotal = stat.getTotalBytes();
    Log.d(TAG, "GB available: " + bytesAvailable / BYTES_TO_GB_FACTOR);
    Log.d(TAG, "GB total: " + bytesTotal / BYTES_TO_GB_FACTOR);
}

}

1 Answers1

-1

If you dig into it more you can get space used by apps, but probability of having correct information is very low.

Refer following post:

How do I discover memory usage of my application in Android?

Community
  • 1
  • 1
Sachin Chandil
  • 17,133
  • 8
  • 47
  • 65
  • I'm not really interested in how much RAM they take while running, I just want their sizes on disk, so what I'm looking for now is how to find the default directories for each category in order to put them in the StatFs stat constructor – Tiberiu Dorian Moşescu Jul 21 '15 at 12:19
  • Default directories that you are asking for is already defined (I mean system apps of android by default creates those directory). – Sachin Chandil Jul 21 '15 at 12:27