Page MenuHomePhabricator

D6377.id21440.diff
No OneTemporary

D6377.id21440.diff

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.os.Bundle;
@@ -12,6 +13,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;
@@ -63,4 +66,31 @@
initialNotification);
promise.resolve(jsReadableNotification);
}
+
+ @ReactMethod
+ public void createChannel(
+ String channelID,
+ String name,
+ int importance,
+ String description) {
+ 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);
+ if (description != null) {
+ channel.setDescription(description);
+ }
+ notificationManager.createNotificationChannel(channel);
+ }
+
+ @Override
+ public Map<String, Object> getConstants() {
+ final Map<String, Object> 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,13 @@
type CommAndroidNotificationsModuleType = {
+removeAllActiveNotificationsForThread: (threadID: string) => void,
+getInitialNotification: () => Promise<?AndroidForegroundMessage>,
+ +createChannel: (
+ channelID: string,
+ name: string,
+ importance: number,
+ description: ?string,
+ ) => 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
@@ -148,13 +148,12 @@
),
);
} 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,
+ 'Comm notifications channel',
+ );
const commAndroidNotificationsEventEmitter = getCommAndroidNotificationsEventEmitter();
this.androidNotificationsEventSubscriptions.push(
commAndroidNotificationsEventEmitter.addListener(

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 9:22 AM (18 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2675613
Default Alt Text
D6377.id21440.diff (3 KB)

Event Timeline