欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android 7.0开发获取存储设备信息的方法

程序员文章站 2024-02-09 11:19:46
本文实例讲述了 android 7.0开发获取存储设备信息的方法。分享给大家供大家参考,具体如下: android 7.0开发相较之前有不少改进,具体可参考前面的文章an...

本文实例讲述了 android 7.0开发获取存储设备信息的方法。分享给大家供大家参考,具体如下:

android 7.0开发相较之前有不少改进,具体可参考前面的文章android7.0版本影响开发的改进分析,这里简单总结一下android 7.0针对存储设备的简单操作方法。

mountpoint

我们通过mountpoint来描述android设备信息

private static class mountpoint {
    string mdescription;
    string mpath;
    boolean misexternal;
    boolean mismounted;
    long mmaxfilesize;
    long mfreespace;
    long mtotalspace;
}

实现mmountpathlist

private final copyonwritearraylist <mountpoint> mmountpathlist = new copyonwritearraylist<mountpoint>();
public void init(context context) {
    mstoragemanager = (storagemanager) context.getsystemservice(context.storage_service);
    final string defaultpath = getdefaultpath();
    logutils.d(tag, "init,defaultpath = " + defaultpath);
    if (!textutils.isempty(defaultpath)) {
      mrootpath = root_path;
    }
    mmountpathlist.clear();
    // check media availability to init mmountpathlist
    storagevolume[] storagevolumelist = mstoragemanager.getvolumelist();
    if (storagevolumelist != null) {
      for (storagevolume volume : storagevolumelist) {
        mountpoint mountpoint = new mountpoint();
        mountpoint.mdescription = volume.getdescription(context);
        mountpoint.mpath = volume.getpath();
        mountpoint.mismounted = ismounted(volume.getpath());
        mountpoint.misexternal = volume.isremovable();
        mountpoint.mmaxfilesize = volume.getmaxfilesize();
        logutils.d(tag, "init,description :" + mountpoint.mdescription + ",path : "
            + mountpoint.mpath + ",ismounted : " + mountpoint.mismounted
            + ",isexternal : " + mountpoint.misexternal + ", mmaxfilesize: " + mountpoint.mmaxfilesize);
        mmountpathlist.add(mountpoint);
      }
    }
    iconmanager.getinstance().init(context, defaultpath + separator);
}

判断是否是外置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) {
    //logutils.d(tag, "isexternalmountpath ,path =" + path);
    if (path == null) {
      return false;
    }
    for (mountpoint mountpoint : mmountpathlist) {
      if (mountpoint.misexternal && mountpoint.mpath.equals(path)) {
        return true;
      }
    }
    return false;
}

判断内置存储空间

public boolean isinternalmountpath(string path) {
    //logutils.d(tag, "isinternalmountpath ,path =" + path);
    if (path == null) {
      return false;
    }
    for (mountpoint mountpoint : mmountpathlist) {
      if (!mountpoint.misexternal && mountpoint.mpath.equals(path)) {
        return true;
      }
    }
    return false;
}

更多关于android相关内容感兴趣的读者可查看本站专题:《android文件操作技巧汇总》、《android视图view技巧总结》、《android编程之activity操作技巧总结》、《android布局layout技巧总结》、《android开发入门与进阶教程》、《android资源操作技巧汇总》及《android控件用法总结

希望本文所述对大家android程序设计有所帮助。