From b1be5949326442ebe9c7b627f39baeb5d70fcd91 Mon Sep 17 00:00:00 2001 From: advplyr Date: Wed, 10 Aug 2022 17:31:38 -0500 Subject: [PATCH] Fix:Android catch exception when grantUriPermission fails --- .../app/player/PlayerNotificationService.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt b/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt index 704194c7..870fabaf 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt @@ -256,11 +256,15 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { // Fix for local images crashing on Android 11 for specific devices // https://stackoverflow.com/questions/64186578/android-11-mediastyle-notification-crash/64232958#64232958 - ctx.grantUriPermission( - "com.android.systemui", - coverUri, - Intent.FLAG_GRANT_READ_URI_PERMISSION - ) + try { + ctx.grantUriPermission( + "com.android.systemui", + coverUri, + Intent.FLAG_GRANT_READ_URI_PERMISSION + ) + } catch(error:Exception) { + Log.e(tag, "Grant uri permission error $error") + } return MediaDescriptionCompat.Builder() .setMediaId(currentPlaybackSession!!.id)