最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 7.0開發(fā)獲取存儲(chǔ)設(shè)備信息的方法

 更新時(shí)間:2017年11月16日 09:59:49   作者:王大錘扛刀  
這篇文章主要介紹了Android 7.0開發(fā)獲取存儲(chǔ)設(shè)備信息的方法,結(jié)合實(shí)例形式分析了Android7.0針對(duì)存儲(chǔ)設(shè)備信息的獲取、判斷操作方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了 Android 7.0開發(fā)獲取存儲(chǔ)設(shè)備信息的方法。分享給大家供大家參考,具體如下:

Android 7.0開發(fā)相較之前有不少改進(jìn),具體可參考前面的文章Android7.0版本影響開發(fā)的改進(jìn)分析,這里簡單總結(jié)一下Android 7.0針對(duì)存儲(chǔ)設(shè)備的簡單操作方法。

MountPoint

我們通過MountPoint來描述android設(shè)備信息

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

實(shí)現(xiàn)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;
}

判斷內(nèi)置存儲(chǔ)空間

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;
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android文件操作技巧匯總》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android布局layout技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

观塘区| 崇信县| 托里县| 沁源县| 古田县| 胶南市| 马边| 墨脱县| 宜都市| 炎陵县| 嘉兴市| 盘锦市| 阿合奇县| 墨竹工卡县| 腾冲县| 宜都市| 东乌珠穆沁旗| 洛阳市| 连云港市| 邹城市| 五大连池市| 昔阳县| 黔江区| 太原市| 连州市| 正定县| 罗田县| 哈密市| 舟山市| 台南市| 遂平县| 平谷区| 武山县| 德化县| 丹寨县| 内丘县| 富顺县| 青河县| 建昌县| 漳州市| 新龙县|