-2

enter image description hereI want to get the free size of (Internal and External) storage of my device. I have following storage on device like : Internal Storage, SD Card, Phone Storage, enter image description here I am able to get Internal and SD Card storage, but not able to get Phone Storage. Please help.

Harshit Rathi
  • 1,862
  • 2
  • 18
  • 25
  • 1
    Internal Storage is the phone storage. Also... this is not even remotely related to programming. – sarveshseri Feb 06 '15 at 10:16
  • Actually the phone storage is divided in two parts : Internal and phone storage in my micromax device. – Harshit Rathi Feb 06 '15 at 10:17
  • I guess your phone does not support SD cards... ? In that case... probably... the other storage which you are calling "phone storage" will be mounted as SD card. – sarveshseri Feb 06 '15 at 10:20
  • According to http://developer.android.com/guide/topics/data/data-storage.html... `Every Android-compatible device supports a shared "external storage" that you can use to save files. This can be a removable storage media (such as an SD card) or an internal (non-removable) storage.` – sarveshseri Feb 06 '15 at 10:23
  • so how can i get these three storage???? – Harshit Rathi Feb 06 '15 at 10:24
  • What three? Also.. What do you mean by "get" ? Android views storage as just two types... `internal` ( The phone memory... where your apps are installed by default ) and `external` ( Can be in-builts in some phones but generally SD card ) – sarveshseri Feb 06 '15 at 10:26
  • As you can see in screen shot : Internal Storage, SD Card Storage, Phone Storage? – Harshit Rathi Feb 06 '15 at 10:27
  • possible duplicate of [How to find the amount of free storage (disk space) left on Android?](http://stackoverflow.com/questions/7115016/how-to-find-the-amount-of-free-storage-disk-space-left-on-android) – Jean-François Corbett Jun 01 '15 at 07:20

2 Answers2

1

See this question, you can get both the internal storage free space and also the SD card free space.

EDIT: from the linked question:

public long freeMemory() { 
    StatFs statFs = new StatFs(Environment.getDataDirectory().getAbsolutePath()); 
    long free = (statFs.getAvailableBlocks() * statFs.getBlockSize());
    return free; 
}

To convert to human readable format (MB, GB, etc.) See the liked question.

Usually (on Chinese phones anyway) the internal storage is divided into two parts, one for apps and app data only, and the other one is mounted as an SD card, for photos, media, etc. Some phones also have an SD card slot which you can also access.

Community
  • 1
  • 1
Jonas Czech
  • 12,018
  • 6
  • 44
  • 65
1
public static long getAvailableStorage() {
        File path = StorageUtils.getCacheDirectory(ApplicationController.getInstance(), true);
        long blockSize = 0;
        long availableBlocks = 0;
        StatFs stat = new StatFs(path.getPath());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            blockSize = stat.getBlockSizeLong();
            availableBlocks = stat.getAvailableBlocksLong();
        } else {
            blockSize = stat.getBlockSize();
            availableBlocks = stat.getAvailableBlocks();
        }
        return availableBlocks * blockSize;
    }

public static File getCacheDirectory(Context context,
        boolean preferExternal) {
    File appCacheDir = null;
    String externalStorageState;
    try {
        externalStorageState = Environment.getExternalStorageState();
    } catch (NullPointerException e) { // (sh)it happens (Issue #660)
        externalStorageState = "";
    }
    if (preferExternal && MEDIA_MOUNTED.equals(externalStorageState)
        && hasExternalStoragePermission(context)) {
        appCacheDir = getExternalCacheDir(context);
    }
    if (appCacheDir == null) {
        appCacheDir = context.getCacheDir();
    }
    if (appCacheDir == null) {
        String cacheDirPath = "/data/data/" + context.getPackageName()
            + "/"+DOWNLOAD_SUB_DIRECTORY+"/";

        appCacheDir = new File(cacheDirPath);
    }
    return appCacheDir;
    }

private static File getExternalCacheDir(Context context) {
    File dataDir = new File(new File(
        Environment.getExternalStorageDirectory(), "Android"), "data");
    File appCacheDir = new File(
        new File(dataDir, context.getPackageName()), DOWNLOAD_SUB_DIRECTORY);
    if (!appCacheDir.exists()) {
        if (!appCacheDir.mkdirs()) {
        L.w("Unable to create external cache directory");
        return null;
        }
        try {
        new File(appCacheDir, ".nomedia").createNewFile();
        } catch (IOException e) {

        }
    }
    return appCacheDir;
    }
Suhail Mehta
  • 5,514
  • 2
  • 23
  • 37