首页 > 系统 > Android > 正文

Android编程获取SD卡路径及剩余容量的方法

2019-10-24 20:14:49
字体:
来源:转载
供稿:网友
这篇文章主要介绍了Android编程获取SD卡路径及剩余容量的方法,涉及Android针对SD卡的状态判断,路径获取及容量计算等相关技巧,需要的朋友可以参考下
 

本文实例讲述了Android编程获取SD卡路径及剩余容量的方法。分享给大家供大家参考,具体如下:

public static String getExternalStoragePath() { // 获取SdCard状态 String state = android.os.Environment.getExternalStorageState(); // 判断SdCard是否存在并且是可用的 if (android.os.Environment.MEDIA_MOUNTED.equals(state)) { if (android.os.Environment.getExternalStorageDirectory().canWrite()) {   return android.os.Environment.getExternalStorageDirectory().getPath(); } } return null;}public static long getAvailableStore(String filePath) { // 取得sdcard文件路径 StatFs statFs = new StatFs(filePath); // 获取block的SIZE long blocSize = statFs.getBlockSize(); // 获取BLOCK数量 // long totalBlocks = statFs.getBlockCount(); // 可使用的Block的数量 long availaBlock = statFs.getAvailableBlocks(); // long total = totalBlocks * blocSize; long availableSpare = availaBlock * blocSize; return availableSpare;}
 


注:相关教程知识阅读请移步到Android开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表