SoFunction
Updated on 2025-03-11

Android 7.0 development method to obtain storage device information

This article describes the method of obtaining storage device information in Android 7.0. Share it for your reference, as follows:

Android 7.0 development has improved a lot compared to the previous one. For details, please refer to the previous article.Analysis of improvements in the development impact of Android 7.0 versionHere is a brief summary of the simple operation methods of Android 7.0 for storage devices.

MountPoint

We use MountPoint to describe android device information

private static class MountPoint {
    String mDescription;
    String mPath;
    boolean mIsExternal;
    boolean mIsMounted;
    long mMaxFileSize;
    long mFreeSpace;
    long mTotalSpace;
}

Implement mMountPathList

private final CopyOnWriteArrayList <MountPoint> mMountPathList = new CopyOnWriteArrayList<MountPoint>();
public void init(Context context) {
    mStorageManager = (StorageManager) (Context.STORAGE_SERVICE);
    final String defaultPath = getDefaultPath();
    (TAG, "init,defaultPath = " + defaultPath);
    if (!(defaultPath)) {
      mRootPath = ROOT_PATH;
    }
    ();
    // check media availability to init mMountPathList
    StorageVolume[] storageVolumeList = ();
    if (storageVolumeList != null) {
      for (StorageVolume volume : storageVolumeList) {
        MountPoint mountPoint = new MountPoint();
         = (context);
         = ();
         = isMounted(());
         = ();
         = ();
        (TAG, "init,description :" +  + ",path : "
            +  + ",isMounted : " + 
            + ",isExternal : " +  + ", mMaxFileSize: " + );
        (mountPoint);
      }
    }
    ().init(context, defaultPath + SEPARATOR);
}

Determine whether it is an external SDcard

/**
* This method checks weather certain path is external mount path.
*
* @param path path which needs to be checked
* @return true for external mount path, and false for not external mount path
*/
public boolean isExternalMountPath(String path) {
    //(TAG, "isExternalMountPath ,path =" + path);
    if (path == null) {
      return false;
    }
    for (MountPoint mountPoint : mMountPathList) {
      if ( && (path)) {
        return true;
      }
    }
    return false;
}

Determine the built-in storage space

public boolean isInternalMountPath(String path) {
    //(TAG, "isInternalMountPath ,path =" + path);
    if (path == null) {
      return false;
    }
    for (MountPoint mountPoint : mMountPathList) {
      if (! && (path)) {
        return true;
      }
    }
    return false;
}

For more information about Android related content, please check out the topic of this site:Android file operation skills summary》、《Android View View Tips Summary》、《Android programming activity operation skills summary》、《Android layout layout tips summary》、《Android development introduction and advanced tutorial》、《Android resource operation skills summary"and"Android control usage summary

I hope this article will be helpful to everyone's Android programming design.