package com.anyun.h264.util;
|
|
import android.content.Context;
|
import android.os.storage.StorageManager;
|
|
import java.lang.reflect.Array;
|
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.Method;
|
|
public class FileUtil {
|
//获取插入的TFCard目录路径
|
public static String getStoragePath(Context mContext, boolean is_removale) {
|
if (mContext != null) {
|
StorageManager mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
|
Class<?> storageVolumeClazz = null;
|
try {
|
storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
|
Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList");
|
Method getPath = storageVolumeClazz.getMethod("getPath");
|
Method isRemovable = storageVolumeClazz.getMethod("isRemovable");
|
Object result = getVolumeList.invoke(mStorageManager);
|
final int length = Array.getLength(result);
|
for (int i = 0; i < length; i++) {
|
Object storageVolumeElement = Array.get(result, i);
|
String path = (String) getPath.invoke(storageVolumeElement);
|
boolean removable = (Boolean) isRemovable.invoke(storageVolumeElement);
|
if (is_removale == removable) {
|
return path;
|
}
|
}
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
} catch (InvocationTargetException e) {
|
e.printStackTrace();
|
} catch (NoSuchMethodException e) {
|
e.printStackTrace();
|
} catch (IllegalAccessException e) {
|
e.printStackTrace();
|
}
|
return null;
|
} else {
|
|
return null;
|
}
|
|
}
|
}
|