diff --git a/CHANGELOG.md b/CHANGELOG.md index c016842..44e628e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 The changes documented here do not include those from the original repository. +## [Unreleased] + +### 2026-10-14 + +- Fix: catch the `SecurityException` thrown by `takePersistableUriPermission` in `IONCAMROpenPhotoPickerActivity` when the picker returns a URI without a persistable grant (seen on Android 11/12), so choosing from the gallery no longer crashes the app ([capacitor-camera#58](https://github.com/ionic-team/capacitor-camera/issues/58)). + ## [1.0.2] ### 2026-07-08 diff --git a/src/main/kotlin/io/ionic/libs/ioncameralib/view/IONCAMROpenPhotoPickerActivity.kt b/src/main/kotlin/io/ionic/libs/ioncameralib/view/IONCAMROpenPhotoPickerActivity.kt index bf77e2a..09b1333 100644 --- a/src/main/kotlin/io/ionic/libs/ioncameralib/view/IONCAMROpenPhotoPickerActivity.kt +++ b/src/main/kotlin/io/ionic/libs/ioncameralib/view/IONCAMROpenPhotoPickerActivity.kt @@ -114,7 +114,13 @@ class IONCAMROpenPhotoPickerActivity : ComponentActivity() { private fun makeUriPermissionPersistable(uri: Uri) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { // only for Android >= 11 - applicationContext.contentResolver.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION) + try { + applicationContext.contentResolver.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION) + } catch (e: SecurityException) { + // Some pickers (GMS-backported photo picker, OEM galleries on Android 11/12) hand back + // URIs with no persistable grant; the temporary read grant is enough to process the media. + Log.w("PhotoPicker", "Could not persist URI permission for $uri", e) + } } }