Android6.0上会根据卡的种类和卡的挂载状态来动态生成挂载路径,所以之前写固定路径的办法不可用,最后通过网上查找和分析android源码,通过反射获取到路径,并且进行了正确区分,代码如下:
/**
* 6.0获取外置sdcard和U盘路径,并区分
* @param mContext
* @param keyword SD = "内部存储"; EXT = "SD卡"; USB = "U盘"
* @return
*/
public static String getStoragePath(Context mContext,String keyword) {
String targetpath = "";
StorageManager mStorageManager = (StorageManager) mContext
.getSystemService(Context.STORAGE_SERVICE);
Class<?> storageVolumeClazz = null;
try {
storageVolumeClazz = Class.forNa