Android读取sd卡

     public static String[] getStoragePaths() {
List<String> pathsList = new ArrayList<String>();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
File externalFolder = Environment.getExternalStorageDirectory();
if (externalFolder != null) {
pathsList.add(externalFolder.getAbsolutePath());
}
} else {
StorageManager storageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
try {
Method method = StorageManager.class.getDeclaredMethod("getVolumePaths");
method.setAccessible(true);
Object result = method.invoke(storageManager);
if (result != null && result instanceof String[]) {
String[] paths = (String[]) result;
StatFs statFs;
for (String path : paths) {
if (!TextUtils.isEmpty(path) && new File(path).exists()) {
statFs = new StatFs(path);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
if (statFs.getBlockCountLong() * statFs.getBlockSizeLong() != ) {
pathsList.add(path);
}
}else{
if (statFs.getBlockCount() * statFs.getBlockSize() != ) {
pathsList.add(path);
}
}
}
}
}
} catch (Exception e) {
File externalFolder = Environment.getExternalStorageDirectory();
if (externalFolder != null) {
pathsList.add(externalFolder.getAbsolutePath());
}
}
}
return pathsList.toArray(new String[pathsList.size()]);
}
上一篇:ALV列、行、单元格颜色设置


下一篇:Android_(控件)使用ListView显示Android系统SD卡的文件列表_02