diff --git a/src/api-impl-jni/app/android_app_NotificationManager.c b/src/api-impl-jni/app/android_app_NotificationManager.c index 2c930529..8c28aeba 100644 --- a/src/api-impl-jni/app/android_app_NotificationManager.c +++ b/src/api-impl-jni/app/android_app_NotificationManager.c @@ -117,6 +117,14 @@ JNIEXPORT void JNICALL Java_android_app_NotificationManager_nativeShowNotificati g_hash_table_add(ongoing_notifications, GINT_TO_POINTER(id)); } +JNIEXPORT void JNICALL Java_android_app_NotificationManager_nativeCancel(JNIEnv *env, jobject this, jint id) +{ + char *id_string = g_strdup_printf("%d", id); + if (portal) + xdp_portal_remove_notification(portal, id_string); + g_free(id_string); +} + static void remove_ongoing_notification(gpointer key, gpointer value, gpointer user_data) { char *id_string = g_strdup_printf("%d", GPOINTER_TO_INT(key)); diff --git a/src/api-impl-jni/generated_headers/android_app_NotificationManager.h b/src/api-impl-jni/generated_headers/android_app_NotificationManager.h index 09778313..4adea60f 100644 --- a/src/api-impl-jni/generated_headers/android_app_NotificationManager.h +++ b/src/api-impl-jni/generated_headers/android_app_NotificationManager.h @@ -31,6 +31,14 @@ JNIEXPORT void JNICALL Java_android_app_NotificationManager_nativeAddAction JNIEXPORT void JNICALL Java_android_app_NotificationManager_nativeShowNotification (JNIEnv *, jobject, jlong, jint, jstring, jstring, jstring, jboolean, jint, jstring, jstring); +/* + * Class: android_app_NotificationManager + * Method: nativeCancel + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_android_app_NotificationManager_nativeCancel + (JNIEnv *, jobject, jint); + #ifdef __cplusplus } #endif diff --git a/src/api-impl/android/app/NotificationManager.java b/src/api-impl/android/app/NotificationManager.java index cd09bb98..b49d4ace 100644 --- a/src/api-impl/android/app/NotificationManager.java +++ b/src/api-impl/android/app/NotificationManager.java @@ -3,6 +3,7 @@ package android.app; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.os.Handler; public class NotificationManager { public void cancelAll() {} @@ -36,7 +37,20 @@ public class NotificationManager { notify(null, id, notification); } - public void cancel(String tag, int id) {} + public void cancel(String tag, final int id) { + // remove_notification doesn't work reliably when sent directly after add_notification in GNOME session. + // So we give some extra delay here. + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + nativeCancel(id); + } + }, 100); + } + + public void cancel(int id) { + cancel(null, id); + } protected static void notificationActionCallback(int id, int intentType, String action, String className) { Context context = Context.this_application; @@ -56,4 +70,5 @@ public class NotificationManager { protected native long nativeInitBuilder(); protected native void nativeAddAction(long builder, String title, int intentType, String action, String className); protected native void nativeShowNotification(long builder, int id, String title, String text, String iconPath, boolean ongoing, int intentType, String action, String className); + protected native void nativeCancel(int id); }