From 3a37a091040d5ffe4007574683d75485e8d31fd7 Mon Sep 17 00:00:00 2001 From: menelike Date: Sat, 24 Feb 2018 16:19:19 +0100 Subject: [PATCH 1/9] - be able to add lines from the payload when using inbox style - use separate inbox per notId --- .../com/adobe/phonegap/push/FCMService.java | 38 +++++++++++++++---- .../adobe/phonegap/push/PushConstants.java | 1 + 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/android/com/adobe/phonegap/push/FCMService.java b/src/android/com/adobe/phonegap/push/FCMService.java index db1738a72..f96f4e36f 100644 --- a/src/android/com/adobe/phonegap/push/FCMService.java +++ b/src/android/com/adobe/phonegap/push/FCMService.java @@ -55,15 +55,15 @@ public class FCMService extends FirebaseMessagingService implements PushConstant private static HashMap> messageMap = new HashMap>(); public void setNotification(int notId, String message) { - ArrayList messageList = messageMap.get(notId); - if (messageList == null) { - messageList = new ArrayList(); - messageMap.put(notId, messageList); - } if (message.isEmpty()) { - messageList.clear(); + messageMap.remove(notId); } else { + ArrayList messageList = messageMap.get(notId); + if (messageList == null) { + messageList = new ArrayList(); + messageMap.put(notId, messageList); + } messageList.add(message); } } @@ -659,13 +659,35 @@ private void setNotificationOngoing(Bundle extras, NotificationCompat.Builder mB private void setNotificationMessage(int notId, Bundle extras, NotificationCompat.Builder mBuilder) { String message = extras.getString(MESSAGE); + String lines = extras.getString(LINES); String style = extras.getString(STYLE, STYLE_TEXT); if (STYLE_INBOX.equals(style)) { setNotification(notId, message); mBuilder.setContentText(fromHtml(message)); - ArrayList messageList = messageMap.get(notId); + ArrayList messageList = new ArrayList(); + if (lines != null) { + setNotification(notId, ""); + try { + JSONArray linesList = new JSONArray(lines); + if (linesList.length() != 0) { + for (int i = 0; i < linesList.length(); i++) { + messageList.add(linesList.optString(i)); + setNotification(notId, linesList.optString(i)); + } + } + } catch (JSONException e) { + // nope + } + } else { + ArrayList cachedMessages = messageMap.get(notId); + messageList.add(message); + for (int i = 0; i < cachedMessages.size(); i++) { + messageList.addAll(cachedMessages); + } + } + Integer sizeList = messageList.size(); if (sizeList > 1) { String sizeListMessage = sizeList.toString(); @@ -677,7 +699,7 @@ private void setNotificationMessage(int notId, Bundle extras, NotificationCompat NotificationCompat.InboxStyle notificationInbox = new NotificationCompat.InboxStyle() .setBigContentTitle(fromHtml(extras.getString(TITLE))).setSummaryText(fromHtml(stacking)); - for (int i = messageList.size() - 1; i >= 0; i--) { + for (int i=0; i Date: Sat, 24 Feb 2018 17:51:46 +0100 Subject: [PATCH 2/9] be able to send silent notifications (don't trigger sound, led, vibration) --- src/android/com/adobe/phonegap/push/FCMService.java | 8 +++++--- src/android/com/adobe/phonegap/push/PushConstants.java | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/android/com/adobe/phonegap/push/FCMService.java b/src/android/com/adobe/phonegap/push/FCMService.java index f96f4e36f..3dcc790a8 100644 --- a/src/android/com/adobe/phonegap/push/FCMService.java +++ b/src/android/com/adobe/phonegap/push/FCMService.java @@ -370,6 +370,7 @@ public void createNotification(Context context, Bundle extras) { String appName = getAppName(this); String packageName = context.getPackageName(); Resources resources = context.getResources(); + int silent = parseInt(SILENT, extras); int notId = parseInt(NOT_ID, extras); Intent notificationIntent = new Intent(this, PushHandlerActivity.class); @@ -429,12 +430,13 @@ public void createNotification(Context context, Bundle extras) { Log.d(LOG_TAG, "stored iconColor=" + localIconColor); Log.d(LOG_TAG, "stored sound=" + soundOption); Log.d(LOG_TAG, "stored vibrate=" + vibrateOption); + Log.d(LOG_TAG, "stored silent=" + silent); /* * Notification Vibration */ - setNotificationVibration(extras, vibrateOption, mBuilder); + if (silent != 1) setNotificationVibration(extras, vibrateOption, mBuilder); /* * Notification Icon Color @@ -476,14 +478,14 @@ public void createNotification(Context context, Bundle extras) { /* * Notification Sound */ - if (soundOption) { + if (silent != 1 && soundOption) { setNotificationSound(context, extras, mBuilder); } /* * LED Notification */ - setNotificationLedColor(extras, mBuilder); + if (silent != 1) setNotificationLedColor(extras, mBuilder); /* * Priority Notification diff --git a/src/android/com/adobe/phonegap/push/PushConstants.java b/src/android/com/adobe/phonegap/push/PushConstants.java index 17759fc43..8b40cbb81 100644 --- a/src/android/com/adobe/phonegap/push/PushConstants.java +++ b/src/android/com/adobe/phonegap/push/PushConstants.java @@ -103,4 +103,5 @@ public interface PushConstants { public static final String LIST_CHANNELS = "listChannels"; public static final String CLEAR_NOTIFICATION = "clearNotification"; public static final String LINES = "lines"; + public static final String SILENT = "silent"; } From a3dc506457d6e7f80380df25d75c46e8bbdbd74b Mon Sep 17 00:00:00 2001 From: menelike Date: Sat, 24 Feb 2018 17:57:09 +0100 Subject: [PATCH 3/9] be able to send visually silenced (no tray updates, no pop ups) content updated messages { contentUpdate: "0" | "1" } --- src/android/com/adobe/phonegap/push/FCMService.java | 13 ++++++++++++- .../com/adobe/phonegap/push/PushConstants.java | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/android/com/adobe/phonegap/push/FCMService.java b/src/android/com/adobe/phonegap/push/FCMService.java index 3dcc790a8..8a7cb8375 100644 --- a/src/android/com/adobe/phonegap/push/FCMService.java +++ b/src/android/com/adobe/phonegap/push/FCMService.java @@ -98,13 +98,24 @@ public void onMessageReceived(RemoteMessage message) { String titleKey = prefs.getString(TITLE_KEY, TITLE); extras = normalizeExtras(applicationContext, extras, messageKey, titleKey); + int contentUpdate = parseInt(CONTENT_UPDATE, extras); if (clearBadge) { PushPlugin.setApplicationIconBadgeNumber(getApplicationContext(), 0); } + if (contentUpdate == 1) { + int notId = parseInt(NOT_ID, extras); + + if (messageMap.containsKey(notId)) { + extras.putBoolean(FOREGROUND, false); + extras.putBoolean(COLDSTART, PushPlugin.isActive()); + + showNotificationIfPossible(applicationContext, extras); + } + } // if we are in the foreground and forceShow is `false` only send data - if (!forceShow && PushPlugin.isInForeground()) { + else if (!forceShow && PushPlugin.isInForeground()) { Log.d(LOG_TAG, "foreground"); extras.putBoolean(FOREGROUND, true); extras.putBoolean(COLDSTART, false); diff --git a/src/android/com/adobe/phonegap/push/PushConstants.java b/src/android/com/adobe/phonegap/push/PushConstants.java index 8b40cbb81..ddc8ae8c0 100644 --- a/src/android/com/adobe/phonegap/push/PushConstants.java +++ b/src/android/com/adobe/phonegap/push/PushConstants.java @@ -104,4 +104,5 @@ public interface PushConstants { public static final String CLEAR_NOTIFICATION = "clearNotification"; public static final String LINES = "lines"; public static final String SILENT = "silent"; + public static final String CONTENT_UPDATE = "contentUpdate"; } From 7f197523093325aba669c36807baf1f774038131 Mon Sep 17 00:00:00 2001 From: menelike Date: Sun, 25 Feb 2018 08:57:11 +0100 Subject: [PATCH 4/9] be able to control the message priority in conjunction with force-show { forceShow: true, foregroundPriority: 1 } --- src/android/com/adobe/phonegap/push/FCMService.java | 9 +++++++-- src/android/com/adobe/phonegap/push/PushConstants.java | 1 + src/android/com/adobe/phonegap/push/PushPlugin.java | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/android/com/adobe/phonegap/push/FCMService.java b/src/android/com/adobe/phonegap/push/FCMService.java index 8a7cb8375..f5d11120a 100644 --- a/src/android/com/adobe/phonegap/push/FCMService.java +++ b/src/android/com/adobe/phonegap/push/FCMService.java @@ -501,7 +501,7 @@ public void createNotification(Context context, Bundle extras) { /* * Priority Notification */ - setNotificationPriority(extras, mBuilder); + setNotificationPriority(context, extras, mBuilder); /* * Notification message @@ -800,12 +800,17 @@ private void setNotificationLedColor(Bundle extras, NotificationCompat.Builder m } } - private void setNotificationPriority(Bundle extras, NotificationCompat.Builder mBuilder) { + private void setNotificationPriority(Context context, Bundle extras, NotificationCompat.Builder mBuilder) { + SharedPreferences prefs = context.getSharedPreferences(PushPlugin.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE); + String foregroundPriority = prefs.getString(FOREGROUND_PRIORITY, null); + boolean foreground = extras.getBoolean(FOREGROUND); String priorityStr = extras.getString(PRIORITY); + if (foreground && foregroundPriority != null) priorityStr = foregroundPriority; if (priorityStr != null) { try { Integer priority = Integer.parseInt(priorityStr); if (priority >= NotificationCompat.PRIORITY_MIN && priority <= NotificationCompat.PRIORITY_MAX) { + Log.d(LOG_TAG, "Priority set to " + priority); mBuilder.setPriority(priority); } else { Log.e(LOG_TAG, "Priority parameter must be between -2 and 2"); diff --git a/src/android/com/adobe/phonegap/push/PushConstants.java b/src/android/com/adobe/phonegap/push/PushConstants.java index ddc8ae8c0..57c7f90f4 100644 --- a/src/android/com/adobe/phonegap/push/PushConstants.java +++ b/src/android/com/adobe/phonegap/push/PushConstants.java @@ -105,4 +105,5 @@ public interface PushConstants { public static final String LINES = "lines"; public static final String SILENT = "silent"; public static final String CONTENT_UPDATE = "contentUpdate"; + public static final String FOREGROUND_PRIORITY = "foregroundPriority"; } diff --git a/src/android/com/adobe/phonegap/push/PushPlugin.java b/src/android/com/adobe/phonegap/push/PushPlugin.java index 690b37776..93e8374fa 100644 --- a/src/android/com/adobe/phonegap/push/PushPlugin.java +++ b/src/android/com/adobe/phonegap/push/PushPlugin.java @@ -252,6 +252,12 @@ public void run() { setApplicationIconBadgeNumber(getApplicationContext(), 0); } + try { + editor.putString(FOREGROUND_PRIORITY, jo.getString(FOREGROUND_PRIORITY)); + } catch (JSONException e) { + Log.d(LOG_TAG, "no foregroundPriority option"); + } + editor.putBoolean(SOUND, jo.optBoolean(SOUND, true)); editor.putBoolean(VIBRATE, jo.optBoolean(VIBRATE, true)); editor.putBoolean(CLEAR_BADGE, clearBadge); @@ -297,6 +303,7 @@ public void run() { editor.remove(CLEAR_NOTIFICATIONS); editor.remove(FORCE_SHOW); editor.remove(SENDER_ID); + editor.remove(FOREGROUND_PRIORITY); editor.commit(); } From 82bbb1f6a68d9d7f4618fbb8f442bddb02da8072 Mon Sep 17 00:00:00 2001 From: menelike Date: Thu, 23 May 2019 16:35:42 +0200 Subject: [PATCH 5/9] be able to distinguish tapped messages in iOS (added tapped (boolean) property to additionalData) --- src/ios/AppDelegate+notification.m | 3 +++ src/ios/PushPlugin.h | 2 ++ src/ios/PushPlugin.m | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/src/ios/AppDelegate+notification.m b/src/ios/AppDelegate+notification.m index b04c47687..6b75c3b7d 100644 --- a/src/ios/AppDelegate+notification.m +++ b/src/ios/AppDelegate+notification.m @@ -121,6 +121,7 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N pushHandler.notificationMessage = userInfo; pushHandler.isInline = NO; + pushHandler.tapped = false; [pushHandler notificationReceived]; } else { NSLog(@"just put it in the shade"); @@ -176,6 +177,7 @@ - (void)pushPluginOnApplicationDidBecomeActive:(NSNotification *)notification { if (self.launchNotification) { pushHandler.isInline = NO; + pushHandler.tapped = true; pushHandler.coldstart = [self.coldstart boolValue]; pushHandler.notificationMessage = self.launchNotification; self.launchNotification = nil; @@ -195,6 +197,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"]; pushHandler.notificationMessage = notification.request.content.userInfo; pushHandler.isInline = YES; + pushHandler.tapped = false; [pushHandler notificationReceived]; completionHandler(UNNotificationPresentationOptionNone); diff --git a/src/ios/PushPlugin.h b/src/ios/PushPlugin.h index 4b6ec930a..21009f709 100644 --- a/src/ios/PushPlugin.h +++ b/src/ios/PushPlugin.h @@ -35,6 +35,7 @@ { NSDictionary *notificationMessage; BOOL isInline; + BOOL tapped; NSString *notificationCallbackId; NSString *callback; BOOL clearBadge; @@ -51,6 +52,7 @@ @property (nonatomic, strong) NSDictionary *notificationMessage; @property BOOL isInline; +@property BOOL tapped; @property BOOL coldstart; @property BOOL clearBadge; @property (nonatomic, strong) NSMutableDictionary *handlerObj; diff --git a/src/ios/PushPlugin.m b/src/ios/PushPlugin.m index 0290c8ecc..17ffdc653 100644 --- a/src/ios/PushPlugin.m +++ b/src/ios/PushPlugin.m @@ -36,6 +36,7 @@ @implementation PushPlugin : CDVPlugin @synthesize notificationMessage; @synthesize isInline; +@synthesize tapped; @synthesize coldstart; @synthesize callbackId; @@ -454,6 +455,12 @@ - (void)notificationReceived { [additionalData setObject:[NSNumber numberWithBool:NO] forKey:@"coldstart"]; } + if (tapped) { + [additionalData setObject:[NSNumber numberWithBool:YES] forKey:@"tapped"]; + } else { + [additionalData setObject:[NSNumber numberWithBool:NO] forKey:@"tapped"]; + } + [message setObject:additionalData forKey:@"additionalData"]; // send notification message @@ -463,6 +470,7 @@ - (void)notificationReceived { self.coldstart = NO; self.notificationMessage = nil; + self.tapped = false; } } From 0a6531318a995ec30afa55ecbf7070bde061c1ab Mon Sep 17 00:00:00 2001 From: menelike Date: Sat, 24 Feb 2018 17:15:29 +0100 Subject: [PATCH 6/9] be able to clear notifications: data: {clearNotifications: [int notId]} props to https://github.com/phonegap/phonegap-plugin-push/pull/2619 --- .../com/adobe/phonegap/push/FCMService.java | 35 +++++++++++++++++++ .../com/adobe/phonegap/push/PushPlugin.java | 11 +++--- src/ios/AppDelegate+notification.m | 35 +++++++++++++++++-- src/ios/PushPlugin.h | 1 + src/ios/PushPlugin.m | 17 +++++---- 5 files changed, 87 insertions(+), 12 deletions(-) diff --git a/src/android/com/adobe/phonegap/push/FCMService.java b/src/android/com/adobe/phonegap/push/FCMService.java index f5d11120a..d66116b6d 100644 --- a/src/android/com/adobe/phonegap/push/FCMService.java +++ b/src/android/com/adobe/phonegap/push/FCMService.java @@ -99,11 +99,28 @@ public void onMessageReceived(RemoteMessage message) { extras = normalizeExtras(applicationContext, extras, messageKey, titleKey); int contentUpdate = parseInt(CONTENT_UPDATE, extras); + String clearNotifications = extras.getString(CLEAR_NOTIFICATIONS); if (clearBadge) { PushPlugin.setApplicationIconBadgeNumber(getApplicationContext(), 0); } + if (clearNotifications != null) { + Log.d(LOG_TAG, clearNotifications); + try { + Log.d(LOG_TAG, "cancel notifications " + clearNotifications); + JSONArray notificationIds = new JSONArray(clearNotifications); + if (notificationIds.length() != 0) { + for (int i = 0; i < notificationIds.length(); i++) { + int clearNotificationId = notificationIds.getInt(i); + PushPlugin.clearNotification(getApplicationContext(), clearNotificationId); + } + } + } catch (JSONException e) { + Log.e(LOG_TAG, "malformed clear notifications =[" + clearNotifications + "]"); + } + } + if (contentUpdate == 1) { int notId = parseInt(NOT_ID, extras); @@ -139,6 +156,24 @@ else if (forceShow && PushPlugin.isInForeground()) { } } } + /* + * Cancel a notification + */ + private void cancelNotification(int notificationId) { + NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + String appName = getAppName(this); + + if (notificationId != 0) { + Log.d(LOG_TAG, "cancel notification id: " + notificationId); + setNotification(notificationId, ""); + try { + notificationManager.cancel(appName, notificationId); + } catch (NullPointerException e) { + Log.e(LOG_TAG, "could not cancel notification id: " + notificationId); + } + } + } + /* * Change a values key in the extras bundle diff --git a/src/android/com/adobe/phonegap/push/PushPlugin.java b/src/android/com/adobe/phonegap/push/PushPlugin.java index 93e8374fa..97b937d7d 100644 --- a/src/android/com/adobe/phonegap/push/PushPlugin.java +++ b/src/android/com/adobe/phonegap/push/PushPlugin.java @@ -541,10 +541,13 @@ private void clearAllNotifications() { } private void clearNotification(int id) { - final NotificationManager notificationManager = (NotificationManager) cordova.getActivity() - .getSystemService(Context.NOTIFICATION_SERVICE); - String appName = (String) this.cordova.getActivity().getPackageManager() - .getApplicationLabel(this.cordova.getActivity().getApplicationInfo()); + PushPlugin.clearNotification(cordova.getActivity(), id); + } + + static void clearNotification(Context context, int id) { + final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + String appName = (String) context.getPackageManager() + .getApplicationLabel(context.getApplicationInfo()); notificationManager.cancel(appName, id); } diff --git a/src/ios/AppDelegate+notification.m b/src/ios/AppDelegate+notification.m index 6b75c3b7d..c18e05be0 100644 --- a/src/ios/AppDelegate+notification.m +++ b/src/ios/AppDelegate+notification.m @@ -96,7 +96,9 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N silent = [contentAvailable integerValue]; } - if (silent == 1) { + NSString * clearNotificationsString = [userInfo objectForKey:@"clearNotifications"]; + // don't wakeup the app on clearNotifications - this is a decision based on performance + if (silent == 1 && clearNotificationsString == nil) { NSLog(@"this should be a silent push"); void (^safeHandler)(UIBackgroundFetchResult) = ^(UIBackgroundFetchResult result){ dispatch_async(dispatch_get_main_queue(), ^{ @@ -124,6 +126,7 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N pushHandler.tapped = false; [pushHandler notificationReceived]; } else { + [self clearNotifications:userInfo]; NSLog(@"just put it in the shade"); //save it for later self.launchNotification = userInfo; @@ -131,6 +134,7 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N } } else { + [self clearNotifications:userInfo]; completionHandler(UIBackgroundFetchResultNoData); } } @@ -188,6 +192,33 @@ - (void)pushPluginOnApplicationDidBecomeActive:(NSNotification *)notification { [[NSNotificationCenter defaultCenter] postNotificationName:pushPluginApplicationDidBecomeActiveNotification object:nil]; } +- (void)clearNotifications:(NSDictionary *)userInfo +{ + PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"]; + + @try { + NSString * clearNotificationsString = [userInfo objectForKey:@"clearNotifications"]; + if (clearNotificationsString != nil) { + clearNotificationsString = [clearNotificationsString stringByReplacingOccurrencesOfString:@"[" withString:@""]; + clearNotificationsString = [clearNotificationsString stringByReplacingOccurrencesOfString:@"]" withString:@""]; + + NSArray * clearNotificationsArray = [clearNotificationsString componentsSeparatedByString:@","]; + + for (NSString *notId in clearNotificationsArray){ + if ([notId isKindOfClass:[NSString class]]) { + NSNumber *clearNotificationId = @([notId integerValue]); + if (clearNotificationId > 0) { + NSLog(@"Push Plugin clearing notId %@", clearNotificationId); + [pushHandler clearRealNotification:clearNotificationId]; + } + } + } + } + } @catch (NSException *exception) { + NSLog(@"Push Plugin could not parse clearNotifications array"); + } +} + - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler @@ -200,7 +231,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center pushHandler.tapped = false; [pushHandler notificationReceived]; - completionHandler(UNNotificationPresentationOptionNone); + completionHandler(UNNotificationPresentationOptionBadge); } - (void)userNotificationCenter:(UNUserNotificationCenter *)center diff --git a/src/ios/PushPlugin.h b/src/ios/PushPlugin.h index 21009f709..a2bc25c58 100644 --- a/src/ios/PushPlugin.h +++ b/src/ios/PushPlugin.h @@ -62,6 +62,7 @@ - (void)subscribe:(CDVInvokedUrlCommand*)command; - (void)unsubscribe:(CDVInvokedUrlCommand*)command; - (void)clearNotification:(CDVInvokedUrlCommand*)command; +- (void)clearRealNotification:(NSNumber*)notId; - (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken; - (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error; diff --git a/src/ios/PushPlugin.m b/src/ios/PushPlugin.m index 17ffdc653..a613c81c5 100644 --- a/src/ios/PushPlugin.m +++ b/src/ios/PushPlugin.m @@ -474,9 +474,8 @@ - (void)notificationReceived { } } -- (void)clearNotification:(CDVInvokedUrlCommand *)command +- (void)clearRealNotification:(NSNumber *)notId { - NSNumber *notId = [command.arguments objectAtIndex:0]; [[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray * _Nonnull notifications) { /* * If the server generates a unique "notId" for every push notification, there should only be one match in these arrays, but if not, it will delete @@ -489,13 +488,19 @@ - (void)clearNotification:(CDVInvokedUrlCommand *)command [matchingNotificationIdentifiers addObject:notification.request.identifier]; } [[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:matchingNotificationIdentifiers]; - - NSString *message = [NSString stringWithFormat:@"Cleared notification with ID: %@", notId]; - CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message]; - [self.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId]; }]; } +- (void)clearNotification:(CDVInvokedUrlCommand *)command +{ + NSNumber *notId = [command.arguments objectAtIndex:0]; + [self clearRealNotification: notId]; + + NSString *message = [NSString stringWithFormat:@"Cleared notification with ID: %@", notId]; + CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message]; + [self.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId]; +} + - (void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command { NSMutableDictionary* options = [command.arguments objectAtIndex:0]; From d089f26c88bfe9134a01625ff2097f0e1beceb4b Mon Sep 17 00:00:00 2001 From: menelike Date: Fri, 24 May 2019 13:47:43 +0200 Subject: [PATCH 7/9] Revert "be able to send visually silenced (no tray updates, no pop ups) content updated messages { contentUpdate: "0" | "1" }" This reverts commit a3dc506457d6e7f80380df25d75c46e8bbdbd74b. --- src/android/com/adobe/phonegap/push/FCMService.java | 13 +------------ .../com/adobe/phonegap/push/PushConstants.java | 1 - 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/android/com/adobe/phonegap/push/FCMService.java b/src/android/com/adobe/phonegap/push/FCMService.java index d66116b6d..de7ec864a 100644 --- a/src/android/com/adobe/phonegap/push/FCMService.java +++ b/src/android/com/adobe/phonegap/push/FCMService.java @@ -98,7 +98,6 @@ public void onMessageReceived(RemoteMessage message) { String titleKey = prefs.getString(TITLE_KEY, TITLE); extras = normalizeExtras(applicationContext, extras, messageKey, titleKey); - int contentUpdate = parseInt(CONTENT_UPDATE, extras); String clearNotifications = extras.getString(CLEAR_NOTIFICATIONS); if (clearBadge) { @@ -121,18 +120,8 @@ public void onMessageReceived(RemoteMessage message) { } } - if (contentUpdate == 1) { - int notId = parseInt(NOT_ID, extras); - - if (messageMap.containsKey(notId)) { - extras.putBoolean(FOREGROUND, false); - extras.putBoolean(COLDSTART, PushPlugin.isActive()); - - showNotificationIfPossible(applicationContext, extras); - } - } // if we are in the foreground and forceShow is `false` only send data - else if (!forceShow && PushPlugin.isInForeground()) { + if (!forceShow && PushPlugin.isInForeground()) { Log.d(LOG_TAG, "foreground"); extras.putBoolean(FOREGROUND, true); extras.putBoolean(COLDSTART, false); diff --git a/src/android/com/adobe/phonegap/push/PushConstants.java b/src/android/com/adobe/phonegap/push/PushConstants.java index 57c7f90f4..e04009ba8 100644 --- a/src/android/com/adobe/phonegap/push/PushConstants.java +++ b/src/android/com/adobe/phonegap/push/PushConstants.java @@ -104,6 +104,5 @@ public interface PushConstants { public static final String CLEAR_NOTIFICATION = "clearNotification"; public static final String LINES = "lines"; public static final String SILENT = "silent"; - public static final String CONTENT_UPDATE = "contentUpdate"; public static final String FOREGROUND_PRIORITY = "foregroundPriority"; } From 514ebe10ba4dac434e1f2cf45509115bace72ab0 Mon Sep 17 00:00:00 2001 From: menelike Date: Fri, 24 May 2019 13:52:43 +0200 Subject: [PATCH 8/9] Revert "be able to control the message priority in conjunction with force-show { forceShow: true, foregroundPriority: 1 }" This reverts commit 7f197523093325aba669c36807baf1f774038131. --- src/android/com/adobe/phonegap/push/FCMService.java | 9 ++------- src/android/com/adobe/phonegap/push/PushConstants.java | 1 - src/android/com/adobe/phonegap/push/PushPlugin.java | 7 ------- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/android/com/adobe/phonegap/push/FCMService.java b/src/android/com/adobe/phonegap/push/FCMService.java index de7ec864a..6086bf697 100644 --- a/src/android/com/adobe/phonegap/push/FCMService.java +++ b/src/android/com/adobe/phonegap/push/FCMService.java @@ -525,7 +525,7 @@ public void createNotification(Context context, Bundle extras) { /* * Priority Notification */ - setNotificationPriority(context, extras, mBuilder); + setNotificationPriority(extras, mBuilder); /* * Notification message @@ -824,17 +824,12 @@ private void setNotificationLedColor(Bundle extras, NotificationCompat.Builder m } } - private void setNotificationPriority(Context context, Bundle extras, NotificationCompat.Builder mBuilder) { - SharedPreferences prefs = context.getSharedPreferences(PushPlugin.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE); - String foregroundPriority = prefs.getString(FOREGROUND_PRIORITY, null); - boolean foreground = extras.getBoolean(FOREGROUND); + private void setNotificationPriority(Bundle extras, NotificationCompat.Builder mBuilder) { String priorityStr = extras.getString(PRIORITY); - if (foreground && foregroundPriority != null) priorityStr = foregroundPriority; if (priorityStr != null) { try { Integer priority = Integer.parseInt(priorityStr); if (priority >= NotificationCompat.PRIORITY_MIN && priority <= NotificationCompat.PRIORITY_MAX) { - Log.d(LOG_TAG, "Priority set to " + priority); mBuilder.setPriority(priority); } else { Log.e(LOG_TAG, "Priority parameter must be between -2 and 2"); diff --git a/src/android/com/adobe/phonegap/push/PushConstants.java b/src/android/com/adobe/phonegap/push/PushConstants.java index e04009ba8..8b40cbb81 100644 --- a/src/android/com/adobe/phonegap/push/PushConstants.java +++ b/src/android/com/adobe/phonegap/push/PushConstants.java @@ -104,5 +104,4 @@ public interface PushConstants { public static final String CLEAR_NOTIFICATION = "clearNotification"; public static final String LINES = "lines"; public static final String SILENT = "silent"; - public static final String FOREGROUND_PRIORITY = "foregroundPriority"; } diff --git a/src/android/com/adobe/phonegap/push/PushPlugin.java b/src/android/com/adobe/phonegap/push/PushPlugin.java index 97b937d7d..98b7c92ce 100644 --- a/src/android/com/adobe/phonegap/push/PushPlugin.java +++ b/src/android/com/adobe/phonegap/push/PushPlugin.java @@ -252,12 +252,6 @@ public void run() { setApplicationIconBadgeNumber(getApplicationContext(), 0); } - try { - editor.putString(FOREGROUND_PRIORITY, jo.getString(FOREGROUND_PRIORITY)); - } catch (JSONException e) { - Log.d(LOG_TAG, "no foregroundPriority option"); - } - editor.putBoolean(SOUND, jo.optBoolean(SOUND, true)); editor.putBoolean(VIBRATE, jo.optBoolean(VIBRATE, true)); editor.putBoolean(CLEAR_BADGE, clearBadge); @@ -303,7 +297,6 @@ public void run() { editor.remove(CLEAR_NOTIFICATIONS); editor.remove(FORCE_SHOW); editor.remove(SENDER_ID); - editor.remove(FOREGROUND_PRIORITY); editor.commit(); } From 1c4bf30ef7c9d619259030a8b27eda85658829e6 Mon Sep 17 00:00:00 2001 From: menelike Date: Fri, 24 May 2019 13:54:37 +0200 Subject: [PATCH 9/9] Revert "be able to send silent notifications (don't trigger sound, led, vibration)" This reverts commit 39a920c102055767d9b8980db4efde34ed54db4f. --- src/android/com/adobe/phonegap/push/FCMService.java | 8 +++----- src/android/com/adobe/phonegap/push/PushConstants.java | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/android/com/adobe/phonegap/push/FCMService.java b/src/android/com/adobe/phonegap/push/FCMService.java index 6086bf697..d29ca9915 100644 --- a/src/android/com/adobe/phonegap/push/FCMService.java +++ b/src/android/com/adobe/phonegap/push/FCMService.java @@ -405,7 +405,6 @@ public void createNotification(Context context, Bundle extras) { String appName = getAppName(this); String packageName = context.getPackageName(); Resources resources = context.getResources(); - int silent = parseInt(SILENT, extras); int notId = parseInt(NOT_ID, extras); Intent notificationIntent = new Intent(this, PushHandlerActivity.class); @@ -465,13 +464,12 @@ public void createNotification(Context context, Bundle extras) { Log.d(LOG_TAG, "stored iconColor=" + localIconColor); Log.d(LOG_TAG, "stored sound=" + soundOption); Log.d(LOG_TAG, "stored vibrate=" + vibrateOption); - Log.d(LOG_TAG, "stored silent=" + silent); /* * Notification Vibration */ - if (silent != 1) setNotificationVibration(extras, vibrateOption, mBuilder); + setNotificationVibration(extras, vibrateOption, mBuilder); /* * Notification Icon Color @@ -513,14 +511,14 @@ public void createNotification(Context context, Bundle extras) { /* * Notification Sound */ - if (silent != 1 && soundOption) { + if (soundOption) { setNotificationSound(context, extras, mBuilder); } /* * LED Notification */ - if (silent != 1) setNotificationLedColor(extras, mBuilder); + setNotificationLedColor(extras, mBuilder); /* * Priority Notification diff --git a/src/android/com/adobe/phonegap/push/PushConstants.java b/src/android/com/adobe/phonegap/push/PushConstants.java index 8b40cbb81..17759fc43 100644 --- a/src/android/com/adobe/phonegap/push/PushConstants.java +++ b/src/android/com/adobe/phonegap/push/PushConstants.java @@ -103,5 +103,4 @@ public interface PushConstants { public static final String LIST_CHANNELS = "listChannels"; public static final String CLEAR_NOTIFICATION = "clearNotification"; public static final String LINES = "lines"; - public static final String SILENT = "silent"; }