Android 7.0开发获取存储设备信息的方法
2017-11-16 09:59
881 查看
本文实例讲述了 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程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- Android通过反射的方法获取手机存储设备的状态信息
- Android开发 httpclient Post方法实现从tomcat服务器(JSP)获取listview信息
- Android开发中获取设备相关信息
- Android开发学习---如何写数据到外部存储设备(sd卡),Environment.getExternalStorageDirectory,怎么获取sd卡的大小?
- 【.NET】C#中各类获取设备存储信息的各类方法
- Android开发之系统信息【1】——获取Android手机中SD卡存储信息
- Android - LayoutParams,小火箭,高内聚低耦合,回调,设备存储空间,获取应用信息
- Android中获取设备信息的方法
- Android软件开发之获取通讯录联系人信息 + android联系人信息的存储结构 + Android联系人读取操作笔记
- Android App开发基础篇—设备屏幕分辨率获取方法
- Android 7.0 得到存储设备信息
- Android开发获取系统中已安装程序信息的方法
- Android与H5混合开发中获取H5存储在localStorage中的数据信息
- iOS App开发中通过UIDevice类获取设备信息的方法
- Android软件开发之获取通讯录联系人信息 + android联系人信息的存储结构 + Android联系人读取操作笔记
- Android软件开发之获取通讯录联系人信息 + android联系人信息的存储结构 + Android联系人读取操作笔记
- Android 开发技巧 - 获取apk签名信息的方法
- Android软件开发之获取通讯录联系人信息 + android联系人信息的存储结构 + Android联系人读取操作笔记
- C#中各类获取设备存储信息的各类方法
- Android开发之获取设备的屏幕信息