From ae2953b7d0a0881f7bb925f0f5d0cf1d3ac9daf4 Mon Sep 17 00:00:00 2001 From: sanduluca <56228534+sanduluca@users.noreply.github.com> Date: Thu, 31 Oct 2024 16:10:05 +0200 Subject: [PATCH] fix(android): add error handling for POST_NOTIFICATIONS permission request (#1135) --- .../io/invertase/notifee/NotifeeApiModule.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/react-native/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java b/packages/react-native/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java index 7ed77c1d..d57abbed 100644 --- a/packages/react-native/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java +++ b/packages/react-native/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java @@ -273,10 +273,17 @@ public void requestPermission(Promise promise) { .setRequestPermissionCallback( (e, aBundle) -> NotifeeReactUtils.promiseResolver(promise, e, aBundle)); - activity.requestPermissions( - new String[] {Manifest.permission.POST_NOTIFICATIONS}, - Notifee.REQUEST_CODE_NOTIFICATION_PERMISSION, - this); + try { + activity.requestPermissions( + new String[] {Manifest.permission.POST_NOTIFICATIONS}, + Notifee.REQUEST_CODE_NOTIFICATION_PERMISSION, + this); + } catch (Exception e) { + Logger.d( + "requestPermission", + "Failed to request POST_NOTIFICATIONS permission: " + e.getMessage()); + NotifeeReactUtils.promiseResolver(promise, e); + } } @ReactMethod