shridutt kothari shridutt kothari - 1 month ago 7
Android Question

How to get access to "/" (root) directory using Storage Access framework

I am trying to get access to

"/"
(root) directory using
Storage Access Framework
on Android 7.0 and above, after looking to the Google sample on GitHub, i can see that there are only predefined directories are passed in while creating accessIntent using StorageVolume class, but how to get access to any other directory than those predefined directories?

Here is my code, which i tried:

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

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


i am getting null as storageVolume and unable to get access to "/" directory using StorageVolume framework.


How to get Scoped Directory Access to
"/"
directory
using Storage Access Framework on Android 7.0 and above?

Answer

You can't get access to root folder if the device is not rooted. See http://stackoverflow.com/a/5293771/4284706, http://stackoverflow.com/a/5436182/4284706 for answers if your device is rooted.