国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 7.0開發獲取存儲設備信息的方法

2019-10-22 18:23:08
字體:
來源:轉載
供稿:網友

本文實例講述了 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開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 赤峰市| 孝义市| 高尔夫| 富蕴县| 库伦旗| 丰镇市| 交城县| 古交市| 九龙城区| 延寿县| 天津市| 滨海县| 湄潭县| 广德县| 田林县| 宁化县| 太仓市| 余姚市| 青铜峡市| 德州市| 乌鲁木齐县| 南昌市| 乌拉特前旗| 绿春县| 平塘县| 团风县| 平遥县| 岳普湖县| 平潭县| 淳化县| 新兴县| 大石桥市| 益阳市| 海原县| 吉隆县| 香格里拉县| 湖州市| 延寿县| 盐池县| 项城市| 泽州县|