有用的方法
来源:互联网 发布:ubuntu sd卡挂载 编辑:程序博客网 时间:2024/06/06 21:45
/** * 获取内置SD卡路径 * */ public static String getPrimaryStoragePath() { try { StorageManager sm = (StorageManager) mContext.getSystemService(Context .STORAGE_SERVICE); Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths", null); String[] paths = (String[]) getVolumePathsMethod.invoke(sm, null); // first element in paths[] is primary storage path return paths[0]; } catch (Exception e) { Log.e(TAG, "getPrimaryStoragePath() failed", e); } return null; }
/** * 获取外置SD卡路径 * */ public static String getSecondaryStoragePath() { try { StorageManager sm = (StorageManager) mContext.getSystemService(Context .STORAGE_SERVICE); Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths", null); String[] paths = (String[]) getVolumePathsMethod.invoke(sm, null); // second element in paths[] is secondary storage path return paths[1]; } catch (Exception e) { Log.e(TAG, "getSecondaryStoragePath() failed", e); } return null; }
public static String getStorageState(String path) { try { StorageManager sm = (StorageManager) mContext.getSystemService(Context .STORAGE_SERVICE); Method getVolumeStateMethod = StorageManager.class.getMethod("getVolumeState", new Class[] {String.class}); String state = (String) getVolumeStateMethod.invoke(sm, path); return state; } catch (Exception e) { Log.e(TAG, "getStorageState() failed", e); } return null; }/** * 判断外置sd卡是否存在 * */ private static boolean isExternalStorageMounted() { StorageManager sm = (StorageManager) mContext.getSystemService(Context .STORAGE_SERVICE); final StorageVolume[] volumes = sm.getVolumeList(); for (StorageVolume v : volumes) { if (v.isRemovable()) { if (Environment.MEDIA_MOUNTED.equals(Environment.getStorageState(v.getPathFile()))) return true; } } return false; }
0 0
- 非常有用的方法
- java有用的方法
- 各种有用的方法
- 有用的方法
- c#中的有用的方法
- c#中的有用的方法
- S60 有用的系统方法
- 比较有用的枚举方法
- 一些有用的搜索方法
- 几个有用的jQuery方法
- Cocos2d 有用的各种方法
- Cocos2d 有用的各种方法
- 可能有用的小方法
- c#中的有用的方法
- JQuery 中有用的方法
- 捕捉异常有用的方法
- BitmapUtil 很多有用的方法
- 一些有用的js方法
- 设计模式——外观模式详解
- 非大数据条件下,使用Array而不是用Vector
- Android:Fragment
- aix 文件夹压缩
- 安装WinPython
- 有用的方法
- 二叉图(高级数据结构)
- jquery中prop()方法和attr()方法的区别浅析
- Abelian Period
- @Autowire注解与自动装配
- 制作北大青鸟视频宣传片列表页面
- 北大青鸟视频宣传片列表
- Abandoned country
- C++11 新特性