Support of URI instead of string path (usage with Storage Access Framework)
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
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.
```dart
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](https://alexrintt.github.io/shared-storage/Usage/Storage%20Access%20Framework/). 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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the Hive.initFlutter entry point and review how the Android database location is currently initialized. Investigate the Storage Access Framework and the referenced shared-storage behavior, then define support for the shown URI argument while preserving access to the selected folder. Done means Hive can initialize its database from a SAF URI on Android 10+.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- databases, mobile-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100