Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3254290
D6227.id21439.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D6227.id21439.diff
View Options
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,49 @@
+package app.comm.android.notifications;
+
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Bundle;
+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()) {
+ Bundle data = notification.getNotification().extras;
+ if (data == null) {
+ continue;
+ }
+ String notificationThreadID = data.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
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 16, 7:41 PM (18 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2501718
Default Alt Text
D6227.id21439.diff (4 KB)
Attached To
Mode
D6227: Implement native Android module that can remove all active notifications for a given thread
Attached
Detach File
Event Timeline
Log In to Comment