How to get permission to external storage directory on Android?

The app I’m developing should be able to scan user’s device for audio files. On Android 4.4 I can access folder /storage/emulated/0 without requesting any permission from the user. On a device with Android 10 I first check for permissions with Permission.RequestUserPermission(Permission.ExternalStorageRead) and Permission.RequestUserPermission(Permission.ExternalStorageWrite). Both of them return true, but when I try to access /storage/emulated/0 I get the UnauthorizedAccessException.
What am I doing wrong? Hot can I get access to the root folder and scan device for audio files?

NVM. Based on this answer I added <application android:requestLegacyExternalStorage="true">. Now everything works perfect!

2 Likes

Thanks for the link.