mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-10 04:37:25 +01:00
fix: storage permission request for non-conforming devices (#726)
* fix: storage permission request for non-conforming devices * fix: catch more specific exception * chore: add toast message to indicate missing persistent permissions * chore: correct newly introduced translaction string * Change error toast message --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
parent
116579d38c
commit
8632ba85ee
@ -111,7 +111,17 @@ object SettingsDataScreen : SearchableSettings {
|
||||
val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
||||
Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
|
||||
context.contentResolver.takePersistableUriPermission(uri, flags)
|
||||
// For some reason InkBook devices do not implement the SAF properly. Persistable URI grants do not
|
||||
// work. However, simply retrieving the URI and using it works fine for these devices. Access is not
|
||||
// revoked after the app is closed or the device is restarted.
|
||||
// This also holds for some Samsung devices. Thus, we simply execute inside of a try-catch block and
|
||||
// ignore the exception if it is thrown.
|
||||
try {
|
||||
context.contentResolver.takePersistableUriPermission(uri, flags)
|
||||
} catch (e: SecurityException) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
context.toast(MR.strings.file_picker_uri_permission_unsupported)
|
||||
}
|
||||
|
||||
UniFile.fromUri(context, uri)?.let {
|
||||
storageDirPref.set(it.uri.toString())
|
||||
|
@ -869,6 +869,7 @@
|
||||
<string name="file_select_cover">Select cover image</string>
|
||||
<string name="file_select_backup">Select backup file</string>
|
||||
<string name="file_picker_error">No file picker app found</string>
|
||||
<string name="file_picker_uri_permission_unsupported">Failed to acquire persistent folder access. The app may behave unexpectedly.</string>
|
||||
<string name="file_null_uri_error">No file selected</string>
|
||||
|
||||
<!--UpdateCheck-->
|
||||
|
Loading…
Reference in New Issue
Block a user