onebusaway-android
onebusaway-android copied to clipboard
[BUG] Backup Storage Functionality Broken on Android 13 and Above - Storage Permissions
Summary:
We got a report from a user with Android version 33
that he can't grant permissions for saving a backup in the storage, I started to investigate and I found that we use permissions READ_EXTERNAL_STORAGE
and WRITE_EXTERNAL_STORAGE
now replaced with READ_MEDIA_IMAGES
and READ_MEDIA_VIDEO
for higher android version from API 33
and above. See android docs
I tested this on my Android 13 emulator and can confirm it's broken.
Useful discussion/articles:
Steps to reproduce:
- Go to the settings
- Try to save a backup to storage
Expected behavior:
Dialog pop-up asking for the permissions
Observed behavior:
No dialog asking for permission
Device and Android version:
Android Version: 13 - API 33
Video
(just caught the issue link, great timing!)
READ_MEDIA_IMAGES
and READ_MEDIA_VIDEO
are not going to be sufficient for your intention
You want to look into ACTION_OPEN_DOCUMENT_TREE
to obtain permissions to write to a folder on external storage (incl. cloud providers).
Note that this uses a androidx.documentfile.provider.DocumentFile
, but this should be sufficient for writing backups.
https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT_TREE
Additional Reading
CommonsWare has a great series on the Android 10/11 storage changes:
https://commonsware.com/blog/2019/10/19/scoped-storage-stories-saf-basics.html
Also see:
- https://developer.android.com/about/versions/11/privacy/storage
- https://source.android.com/docs/core/storage/scoped
Thanks for your help. I appreciate it!