hive
hive copied to clipboard
Support of URI instead of string path (usage with Storage Access Framework)
The current implementation only support a string path as DB location.
This approach is no longer supported on Android 10+ (API 29+) and though new, this API is marked as deprecated and should be migrated to a scoped-storage approach (Storage Access Framework).
Describe the solution you'd like Add support of of URI when initializing Hive DB.
await Hive.initFlutter(uri: fromSafAllowedURI);
Describe alternatives you've considered The thing i'm trying to do is to write the database into the "documents" folder of my Android phone. With standard READ/WRITE access I can already do this with the current implementation. The problem occurs when I delete my app and then reinstall it, the DB belong to the previous version and so cannot be read by the new one without getting perm from the user (done via the intent ACTION_OPEN_DOCUMENT_TREE).
The only way for me to get it work is to ask for MANAGE_EXTERNAL_STORAGE perm. But Google refuse the app if it's not used as a core feature.
Some lib already provide support of SAF like this one. But it return an URI. Converting the URI into a file path make the perm most during the transaction and so we don't have the write access on the selected folder.
Version
- Platform: Android 12
- Flutter version: 3.0.5
- Hive version: 2.2.3