1 public static String[] getStoragePaths() { 2 List<String> pathsList = new ArrayList<String>(); 3 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { 4 File externalFolder = Environment.getExternalStorageDirectory(); 5 if (externalFolder != null) { 6 pathsList.add(externalFolder.getAbsolutePath()); 7 } 8 } else { 9 StorageManager storageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE); 10 try { 11 Method method = StorageManager.class.getDeclaredMethod("getVolumePaths"); 12 method.setAccessible(true); 13 Object result = method.invoke(storageManager); 14 if (result != null && result instanceof String[]) { 15 String[] paths = (String[]) result; 16 StatFs statFs; 17 for (String path : paths) { 18 if (!TextUtils.isEmpty(path) && new File(path).exists()) { 19 statFs = new StatFs(path); 20 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { 21 if (statFs.getBlockCountLong() * statFs.getBlockSizeLong() != 0) { 22 pathsList.add(path); 23 } 24 }else{ 25 if (statFs.getBlockCount() * statFs.getBlockSize() != 0) { 26 pathsList.add(path); 27 } 28 } 29 } 30 } 31 } 32 } catch (Exception e) { 33 File externalFolder = Environment.getExternalStorageDirectory(); 34 if (externalFolder != null) { 35 pathsList.add(externalFolder.getAbsolutePath()); 36 } 37 } 38 } 39 return pathsList.toArray(new String[pathsList.size()]); 40 }
© 著作权归作者所有
举报
发表评论
0/200