Page MenuHomePhabricator

D6377.id21369.diff
No OneTemporary

D6377.id21369.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.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,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
@@ -136,13 +136,12 @@
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);
+ 'Default_1',
+ 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, 8:54 AM (17 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2676444
Default Alt Text
D6377.id21369.diff (3 KB)

Event Timeline