本文实例讲述了 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,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 7.0开发获取存储设备信息的方法全部内容,希望文章能够帮你解决Android 7.0开发获取存储设备信息的方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)