Example usage for android.os.storage StorageManager getVolumeList

List of usage examples for android.os.storage StorageManager getVolumeList

Introduction

In this page you can find the example usage for android.os.storage StorageManager getVolumeList.

Prototype

public @NonNull StorageVolume[] getVolumeList() 

Source Link

Usage

From source file:com.mediatek.contacts.activities.ActivitiesUtils.java

private static int getAvailableStorageCount(Activity activity) {
    int storageCount = 0;
    final StorageManager storageManager = (StorageManager) activity.getApplicationContext()
            .getSystemService(activity.STORAGE_SERVICE);
    if (null == storageManager) {
        Log.w(TAG, "[getAvailableStorageCount]storageManager is null,return 0.");
        return 0;
    }/*from w w w.j  a v  a  2 s . c o m*/
    StorageVolume[] volumes = storageManager.getVolumeList();
    for (StorageVolume volume : volumes) {
        String path = volume.getPath();
        if (!Environment.MEDIA_MOUNTED.equals(storageManager.getVolumeState(path))) {
            continue;
        }
        storageCount++;
    }
    Log.d(TAG, "[getAvailableStorageCount]storageCount = " + storageCount);
    return storageCount;
}

From source file:com.android.mms.ui.MessageUtils.java

public static boolean existingSD(Context context, boolean isExternal) {
    StorageManager mStorageMamatger;
    mStorageMamatger = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
    StorageVolume[] volumes = mStorageMamatger.getVolumeList();
    if (volumes == null) {
        return false;
    }//  ww w  .  j  av a 2s .com
    String mountPoint = null;
    for (int i = 0; i < volumes.length; i++) {
        if (isExternal) {
            if (volumes[i].isRemovable()) {
                mountPoint = volumes[i].getPath();
                break;
            }
        } else {
            if (!volumes[i].isRemovable()) {
                mountPoint = volumes[i].getPath();
                break;
            }
        }
    }
    if (mountPoint == null) {
        return false;
    }
    String volumeState = mStorageMamatger.getVolumeState(mountPoint);
    return (volumeState != null && volumeState.equals(Environment.MEDIA_MOUNTED));
}