如何使用Storage Access框架访问“/”(根)目录

时间:2016-11-04 09:52:32

标签: android android-7.0-nougat android-7.1-nougat

我试图在Android 7.0及更高版本上使用"/"访问Storage Access Framework(root)目录,在查看GitHub上的Google示例后,我可以看到有在使用StorageVolume类创建accessIntent时,只传入预定义的目录,但是如何访问除这些预定义目录之外的任何其他目录?

这是我的代码,我尝试过:

    StorageManager storageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
    File root = new File("/");
    StorageVolume storageVolume = storageManager.getStorageVolume(root);

    Intent intent = storageVolume.createAccessIntent("/");
    startActivityForResult(intent, REQUEST_CODE);

我作为storageVolume获取null并且无法使用StorageVolume框架访问“/”目录。

  

如何将Scoped Directory Access转到"/"目录   在Android 7.0及更高版本上使用Storage Access Framework

1 个答案:

答案 0 :(得分:2)

如果设备未植根,则无法访问根文件夹。 如果您的设备已植根,请参阅https://stackoverflow.com/a/5293771/4284706https://stackoverflow.com/a/5436182/4284706以获取答案。