标签:android style class java tar ext
Environment.getExternalStorageDirectory().getAbsoluteFile();
只能得到系统的SD卡路径,对于对个SD卡的国产神机,想得到外部SD卡就无能为力了。
package com.itheima.mobilesafe.utils;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.os.storage.StorageManager;
public class ExternalMemoryUtils {/**
* 得到所有的外部存储路径,以集合的形式返回** @param context* 上下文* @return SD卡路径集合*/
public static List<String> getExternalMemoryPaths(Context context) {
List<String> list = null;
StorageManager storageManager = (StorageManager) context
.getSystemService(Context.STORAGE_SERVICE);
try {
Class<?>[] paramClasses = {};
Method getVolumePathsMethod = StorageManager.class.getMethod(
"getVolumePaths", paramClasses);// 返回所有安装卷路径列表
getVolumePathsMethod.setAccessible(true);
Object[] params = {};
Object invoke = getVolumePathsMethod.invoke(storageManager, params);
list = new ArrayList<String>();
for (int i = 0; i < ((String[]) invoke).length; i++) {
String path = ((String[]) invoke)[i];
list.add(path);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return list;
}
}
获取手机SD卡路径(国产神机多个SD卡),布布扣,bubuko.com
标签:android style class java tar ext
原文地址:http://www.cnblogs.com/loveandroid/p/3801596.html