diff --git a/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotifications.java b/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotifications.java --- a/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotifications.java +++ b/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotifications.java @@ -4,6 +4,7 @@ import android.app.NotificationManager; import android.content.Context; import android.service.notification.StatusBarNotification; +import androidx.core.app.NotificationManagerCompat; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; @@ -90,6 +91,14 @@ notificationManager.cancelAll(); } + @ReactMethod + public void hasPermission(Promise promise) { + Boolean enabled = + NotificationManagerCompat.from(getReactApplicationContext()) + .areNotificationsEnabled(); + promise.resolve(enabled); + } + @Override public Map getConstants() { final Map constants = new HashMap<>(); diff --git a/native/push/android.js b/native/push/android.js --- a/native/push/android.js +++ b/native/push/android.js @@ -11,6 +11,7 @@ +getConstants: () => { NOTIFICATIONS_IMPORTANCE_HIGH: number, ... }, +setBadge: (count: number) => void, +removeAllDeliveredNotifications: () => void, + +hasPermission: () => Promise, ... }; export type AndroidForegroundMessage = { diff --git a/native/push/push-handler.react.js b/native/push/push-handler.react.js --- a/native/push/push-handler.react.js +++ b/native/push/push-handler.react.js @@ -323,7 +323,7 @@ async ensureAndroidPushNotifsEnabled() { const firebase = getFirebase(); - const hasPermission = await firebase.messaging().hasPermission(); + const hasPermission = await CommAndroidNotifications.hasPermission(); if (!hasPermission) { this.failedToRegisterPushPermissions(); return;