In Android Q direct File access is disabled by default for the apps outside their private folders. Here few strategies you can use in your case:
- Use the manifest option
requestLegacyExternalStorage
to have the old behavior but it won’t work anymore with Android R, so it’s really a short term solution; - Save your files using
getExternalFilesDir()
method. It’s your private folder, other apps could access these files only if they haveREAD_EXTERNAL_STORAGE
permission. In this case it would be good to useFileProvider
to grant access to other apps to your files. - Use the method
getPrimaryStorageVolume().createOpenDocumentTreeIntent()
of classStorageManager
to ask for access to the extenal primary volume. In this case you need user consent and you won’t be able to useFile
api directly anyway, but usingDocumentFile
class you have a very similar interface, so this is the solution closer to the old behavior. It works if you need to perform operations in foreground and background, i.e. without user interaction with the exception the first interaction to request the permission.
I link Flipper library for point 3, it helps to manage files like in older android versions.