Android 7.0开发获取存储设备信息的方法
作者:王大锤扛刀 发布时间:2022-05-24 01:04:57
标签:Android7.0,存储设备
本文实例讲述了 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程序设计有所帮助。
来源:http://blog.csdn.net/wangjicong_215/article/details/76573014


猜你喜欢
- 前言最近遇到想要实现三指滑动监听的需求,实现代码不方便贴出来,但是思路还是可以记录一下。Muilti-touch 双指缩放探索首先要实现On
- 话不多说,请看代码/// <summary>/// 判断字符串是否是数字/// </summary>public s
- 通过子类调用父类的变量,有两种方法:1、把父类的变量设置成public:package triangle.opengl.wlz.stu.ch
- namespace ConsoleApplication1{ using System; &n
- 本文实例为大家分享了Android实现注册界面的具体代码,供大家参考,具体内容如下LinearLayout 控制布局TextView 用于显
- 1、使用Adobe PDF Reader控件。从COM组件库中找到Adobe PDF Reader控件,添加到工具箱中。从工具箱中拖入PDF
- 通常在使用service更新应用时最常出现的问题就是Notification进度的更新问题、service在什么时间关闭以及需要我们自己在S
- 本文实例为大家分享了Android实现蒙板效果的相关代码,供大家参考,具体内容如下1、不保留标题栏蒙板的实现效果:原理:1、弹窗时,设置背景
- 前言在移动互联网浪潮中,联网APP已经把单机拍死在沙滩上,很多公司都希望自家应用能够有一套帐号系统,可是许多用户却并不一定买账:
- 好几年没写博客了,很多知识不记是真的会忘记,以后还是保持写博客的习惯吧。坚持不一定成功,但放弃一定很舒服!(开玩笑(#^.^#))回归正题,
- 先给大家展示效果图,如果感觉还不错,请参考实例代码效果图如下所示:具体代码如下:private void initData() { Bmob
- C#使用GET、POST请求获取结果,这里以一个简单的用户登陆为例。1、 使用GET请求获取结果1.1 创建LoginHandler.asp
- RestTemplate未设置超时时间,导致RabbitMQ队列大量堆积,消费者假死,不进行消费,类似线程堵塞。排查:从日志排查问题,在从进
- 一、length()返回此字符串的长度public static void main4(String[] args) { &n
- Eureka大白话解析笔记补录:1.Eureka 介绍Spring Cloud Eureka 是 Spring Clou
- 概况Java的Long类主要的作用就是对基本类型long进行封装,提供了一些处理long类型的方法,比如long到String类型的转换方法
- 背景:有时候string类型的数据取出来是个很标准的key、value形式,通过Gson的可以直接转成map使用方式:Gson gson =
- 说点对这几个容易混淆的词的理解:1、c++中的virtual方法的 virtual关键字主要是防止继承中重复继承父类的同一个方法而设置的标识
- 基本概念servlet 关系servlet 和 servletconfig 是一对一的关系;servletconfig 作用它存储 web.
- 最近过年发红包拜年成为一种新的潮流,作为程序猿对算法的好奇远远要大于对红包的好奇,这里介绍一种自己想到的一种随机红包分配策略,还请大家多多指