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 @@ -1,5 +1,6 @@ package app.comm.android.notifications; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.service.notification.StatusBarNotification; @@ -11,6 +12,8 @@ import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.WritableMap; import com.google.firebase.messaging.RemoteMessage; +import java.util.HashMap; +import java.util.Map; public class CommAndroidNotifications extends ReactContextBaseJavaModule { private NotificationManager notificationManager; @@ -59,4 +62,24 @@ initialNotification); promise.resolve(jsReadableNotification); } + + @ReactMethod + public void createChannel(String channelID, String name, int importance) { + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) { + // Method used below appeared in API level 26. Details: + // https://developer.android.com/develop/ui/views/notifications/channels#CreateChannel + return; + } + NotificationChannel channel = + new NotificationChannel(channelID, name, importance); + notificationManager.createNotificationChannel(channel); + } + + @Override + public Map getConstants() { + final Map constants = new HashMap<>(); + constants.put( + "NOTIFICATIONS_IMPORTANCE_HIGH", NotificationManager.IMPORTANCE_HIGH); + return constants; + } } diff --git a/native/push/android.js b/native/push/android.js --- a/native/push/android.js +++ b/native/push/android.js @@ -7,6 +7,8 @@ type CommAndroidNotificationsModuleType = { +removeAllActiveNotificationsForThread: (threadID: string) => void, +getInitialNotification: () => Promise, + +createChannel: (channelID: string, name: string, importance: number) => void, + +getConstants: () => { NOTIFICATIONS_IMPORTANCE_HIGH: number, ... }, ... }; 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 @@ -136,13 +136,11 @@ this.iosNotificationOpened, ); } else if (Platform.OS === 'android') { - const firebase = getFirebase(); - const channel = new firebase.notifications.Android.Channel( + CommAndroidNotifications.createChannel( androidNotificationChannelID, 'Default', - firebase.notifications.Android.Importance.Max, - ).setDescription('Comm notifications channel'); - firebase.notifications().android.createChannel(channel); + CommAndroidNotifications.getConstants().NOTIFICATIONS_IMPORTANCE_HIGH, + ); const commAndroidNotificationsEventEmitter = getCommAndroidNotificationsEventEmitter(); this.androidNotificationsEventSubscriptions.push( commAndroidNotificationsEventEmitter.addListener(