Android 7.0 得到存储设备信息
2017-08-02 11:16
381 查看
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 7.0开发获取存储设备信息的方法
- Android通过反射的方法获取手机存储设备的状态信息
- Android 获得挂载的存储设备信息
- Android - LayoutParams,小火箭,高内聚低耦合,回调,设备存储空间,获取应用信息
- 得到android手机存储信息
- Android软件开发之获取通讯录联系人信息 + android联系人信息的存储结构 + Android联系人读取操作笔记
- android 7.0 databases sharedPreference 存储位置变化
- android获取设备和应用信息
- IOS/Android 读取蓝牙设备电量信息
- android安卓APP获取手机设备信息和手机号码的代码示例
- Android设备的显示信息
- Android usb client mass-storage 多存储设备挂载问题解决
- Android设备信息、感应器检测
- 获取Android手机中SD卡存储信息
- android联系人信息的存储结构
- Android ADB命令大全(通过ADB命令查看wifi密码、MAC地址、设备信息、操作文件、查看文件、日志信息、卸载、启动和安装APK等)
- android联系人信息的存储结构
- Android 获取设备网卡信息
- Android系统应用信息中存储和缓存的计算方法
- Cryptsetup加密存储设备之二(Android篇)