Android 6 SdCard Path

Get from :
https://github.com/1hakr/AnExplorer/blob/master/app/src/main/java/dev/dworks/apps/anexplorer/provider/ExternalStorageProvider.java

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);
        }
    }
}
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); } }}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值