- 直接使用如下方法即可
- private static String getStoragePath(Context mContext, boolean is_removale) {
- 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;
- }
-
引用自:http://blog.csdn.net/u010838555/article/details/51783384
外置sd卡cache 目录,context.getExternalCacheDir.toString()
/sd卡目录/Android/data/this.getPackageName()/cache/
android 6.0 获取外置SD卡路径方法
最新推荐文章于 2024-05-24 16:53:20 发布