Android StorageManager getStorageVolume(file) to search for file by name
I am trying to use android storageManager to search all volumes mounted on the android device including removable (sd card and usb storage) by only knowing the file name. I am using target api 24 and testing on android 7.1.
I can get all the storage volumes with this
List<StorageVolume> allvolumes = mStorageManager.getStorageVolumes(); Log.i(TAG, "All Volumes = " + allvolumes.toString());
I am trying to get the specific volume that has the filename "video.webm" on it. The file does exist on the volume. I am trying this below but I know I am doing something wrong most likely with the file var creation.
here is a link to the getStorageVolume docs
File file = new File("video.webm"); StorageVolume finalvolume = mStorageManager.getStorageVolume(file); //finalvolume always is null, when it should be the name of a volume Log.i(TAG, "finalvolume = " + finalvolume);
- Do i need to have permission to read from the volume before I can even use getStorageVolume(file)?
- I know how to request runtime permission for the whole volume already, but I wanted to search the volume for the file first, then request permissions to read - write for only that specific volume that has the file on it. I dont want to ask for permission on all the volumes.
- the file I am searching for is in the top level of the volume and not in any subfolders.
- when creating the file var, do I have to provide a full path to it, if so, how, when I would not know the path name to each of the volumes.
When I do request runtime permissions for the volume, I have been reading the files using content:// paths a working content path looks something like this