Page MenuHomePhabricator

D6227.id21239.diff
No OneTemporary

D6227.id21239.diff

diff --git a/native/android/app/src/main/java/app/comm/android/MainApplication.java b/native/android/app/src/main/java/app/comm/android/MainApplication.java
--- a/native/android/app/src/main/java/app/comm/android/MainApplication.java
+++ b/native/android/app/src/main/java/app/comm/android/MainApplication.java
@@ -6,6 +6,7 @@
import androidx.annotation.NonNull;
import androidx.multidex.MultiDexApplication;
import app.comm.android.newarchitecture.MainApplicationReactNativeHost;
+import app.comm.android.notifications.CommAndroidNotificationsPackage;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
@@ -44,6 +45,7 @@
packages.add(new RNFirebaseMessagingPackage());
packages.add(new RNFirebaseNotificationsPackage());
packages.add(new KeyboardInputPackage(this.getApplication()));
+ packages.add(new CommAndroidNotificationsPackage());
return packages;
}
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
new file mode 100644
--- /dev/null
+++ b/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotifications.java
@@ -0,0 +1,45 @@
+package app.comm.android.notifications;
+
+import android.app.NotificationManager;
+import android.content.Context;
+import android.service.notification.StatusBarNotification;
+import com.facebook.react.bridge.NativeModule;
+import com.facebook.react.bridge.ReactApplicationContext;
+import com.facebook.react.bridge.ReactContext;
+import com.facebook.react.bridge.ReactContextBaseJavaModule;
+import com.facebook.react.bridge.ReactMethod;
+
+public class CommAndroidNotifications extends ReactContextBaseJavaModule {
+ private NotificationManager notificationManager;
+
+ CommAndroidNotifications(ReactApplicationContext reactContext) {
+ super(reactContext);
+ Context context = reactContext.getApplicationContext();
+ this.notificationManager = (NotificationManager)context.getSystemService(
+ Context.NOTIFICATION_SERVICE);
+ }
+
+ @Override
+ public String getName() {
+ return "CommAndroidNotifications";
+ }
+
+ @ReactMethod
+ public void removeAllActiveNotificationsForThread(String threadID) {
+ if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
+ // Method used below appeared in API level 23. Details:
+ // https://developer.android.com/reference/android/app/NotificationManager#getActiveNotifications()
+ // https://developer.android.com/reference/android/os/Build.VERSION_CODES#M
+ return;
+ }
+ for (StatusBarNotification notification :
+ notificationManager.getActiveNotifications()) {
+ String notificationThreadID =
+ notification.getNotification().extras.getString("threadID");
+ if (notificationThreadID != null &&
+ notificationThreadID.equals(threadID)) {
+ notificationManager.cancel(notification.getTag(), notification.getId());
+ }
+ }
+ }
+}
diff --git a/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotificationsPackage.java b/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotificationsPackage.java
new file mode 100644
--- /dev/null
+++ b/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotificationsPackage.java
@@ -0,0 +1,28 @@
+package app.comm.android.notifications;
+
+import com.facebook.react.ReactPackage;
+import com.facebook.react.bridge.NativeModule;
+import com.facebook.react.bridge.ReactApplicationContext;
+import com.facebook.react.uimanager.ViewManager;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class CommAndroidNotificationsPackage implements ReactPackage {
+
+ @Override
+ public List<ViewManager>
+ createViewManagers(ReactApplicationContext reactContext) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public List<NativeModule>
+ createNativeModules(ReactApplicationContext reactContext) {
+ List<NativeModule> modules = new ArrayList<>();
+
+ modules.add(new CommAndroidNotifications(reactContext));
+
+ return modules;
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 16, 7:29 PM (19 h, 14 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2501589
Default Alt Text
D6227.id21239.diff (4 KB)

Event Timeline