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 @@ -5,6 +5,7 @@ import android.content.Context; import android.os.Bundle; 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; @@ -101,6 +102,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 @@ -16,6 +16,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 @@ -324,7 +324,7 @@ async ensureAndroidPushNotifsEnabled() { const firebase = getFirebase(); - const hasPermission = await firebase.messaging().hasPermission(); + const hasPermission = await CommAndroidNotifications.hasPermission(); if (!hasPermission) { this.failedToRegisterPushPermissions(); return;