Get from :https://github.com/1hakr/AnExplorer/blob/master/app/src/main/java/dev/dworks/apps/anexplorer/provider/ExternalStorageProvider.javaprivate void updateVolumesLocked() { mRoots.clear(); int count = 0; StorageUtils storageUtils = new StorageUtils(getContext()); for (StorageVolume storageVolume : storageUtils.getStorageMounts()) { final File path = storageVolume.getPathFile(); String state = EnvironmentCompat.getStorageState(path); final boolean mounted = Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state); if (!mounted) continue; final String rootId; final String title; if (storageVolume.isPrimary()) { rootId = ROOT_ID_PRIMARY_EMULATED; title = getContext().getString(R.string.root_internal_storage); } else if (storageVolume.getUuid() != null) { rootId = ROOT_ID_SECONDARY + storageVolume.getUuid(); String label = storageVolume.getUserLabel(); title = !TextUtils.isEmpty(label) ? label : getContext().getString(R.string.root_external_storage) + (count > 0 ? " " + count : ""); count++; } else { Log.d(TAG, "Missing UUID for " + storageVolume.getPath() + "; skipping"); continue; } if (mRoots.containsKey(rootId)) { Log.w(TAG, "Duplicate UUID " + rootId + "; skipping"); continue; } try { if(null == path.listFiles()){ continue; } final RootInfo root = new RootInfo(); mRoots.put(rootId, root); root.rootId = rootId; root.flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_EDIT | Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD; root.title = title; root.path = path; root.docId = getDocIdForFile(path); } catch (FileNotFoundException e) { throw new IllegalStateException(e); } }}private void updateVolumesLocked() { mRoots.clear(); int count = 0; StorageUtils storageUtils = new StorageUtils(getContext()); for (StorageVolume storageVolume : storageUtils.getStorageMounts()) { final File path = storageVolume.getPathFile(); String state = EnvironmentCompat.getStorageState(path); final boolean mounted = Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state); if (!mounted) continue; final String rootId; final String title; if (storageVolume.isPrimary()) { rootId = ROOT_ID_PRIMARY_EMULATED; title = getContext().getString(R.string.root_internal_storage); } else if (storageVolume.getUuid() != null) { rootId = ROOT_ID_SECONDARY + storageVolume.getUuid(); String label = storageVolume.getUserLabel(); title = !TextUtils.isEmpty(label) ? label : getContext().getString(R.string.root_external_storage) + (count > 0 ? " " + count : ""); count++; } else { Log.d(TAG, "Missing UUID for " + storageVolume.getPath() + "; skipping"); continue; } if (mRoots.containsKey(rootId)) { Log.w(TAG, "Duplicate UUID " + rootId + "; skipping"); continue; } try { if(null == path.listFiles()){ continue; } final RootInfo root = new RootInfo(); mRoots.put(rootId, root); root.rootId = rootId; root.flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_EDIT | Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD; root.title = title; root.path = path; root.docId = getDocIdForFile(path); } catch (FileNotFoundException e) { throw new IllegalStateException(e); } } }
Android 6 SdCard Path
最新推荐文章于 2022-10-19 11:06:04 发布
本文介绍了一个文件管理应用中用于更新存储卷信息的方法。通过遍历获取到的所有存储设备,并检查其挂载状态来决定是否将其加入到管理列表中。对于不同的存储类型(如内部存储、外部带有UUID的存储等),赋予了不同的标识符和展示名称。
1999

被折叠的 条评论
为什么被折叠?



