Skip to content

Commit 59e5a71

Browse files
committed
Fix Android handler
* Add in-app message handler listener * Fix grouped notification parsing, not add to JSON if is an empty array * Fix action id, make it optional * Add notification open handler listener
1 parent 586e7e4 commit 59e5a71

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

android/src/main/java/com/onesignal/flutter/OneSignalPlugin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ private void setAppId(MethodCall call, Result reply) {
140140
String appId = call.argument("appId");
141141
Context context = flutterRegistrar.activeContext();
142142

143+
OneSignal.setInAppMessageClickHandler(this);
143144
OneSignal.initWithContext(context);
144145
OneSignal.setAppId(appId);
145146

146-
if (hasSetRequiresPrivacyConsent)
147+
if (hasSetRequiresPrivacyConsent && !OneSignal.userProvidedPrivacyConsent())
147148
this.waitingForUserPrivacyConsent = true;
148149
else
149150
this.addObservers();
@@ -156,6 +157,7 @@ private void addObservers() {
156157
OneSignal.addEmailSubscriptionObserver(this);
157158
OneSignal.addPermissionObserver(this);
158159
OneSignal.setNotificationWillShowInForegroundHandler(this);
160+
OneSignal.setNotificationOpenedHandler(this);
159161
}
160162

161163
private void setLogLevel(MethodCall call, Result reply) {

android/src/main/java/com/onesignal/flutter/OneSignalSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static HashMap<String, Object> convertNotificationToMap(OSNotification notificat
106106

107107
hash.put("androidNotificationId", notification.getAndroidNotificationId());
108108

109-
if (notification.getGroupedNotifications() != null) {
109+
if (notification.getGroupedNotifications() != null && !notification.getGroupedNotifications().isEmpty()) {
110110
JSONArray payloadJsonArray = new JSONArray();
111111
for (OSNotification groupedNotification : notification.getGroupedNotifications())
112112
payloadJsonArray.put(groupedNotification.toJSONObject());

lib/src/notification.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ class OSNotificationAction {
292292

293293
/// The ID of the button on your notification
294294
/// that the user tapped
295-
late String actionId;
295+
String? actionId;
296296

297297
OSNotificationAction(Map<String, dynamic> json) {
298298
this.type = OSNotificationActionType.opened;
299-
this.actionId = json['id'] as String;
299+
this.actionId = json['id'] as String?;
300300

301301
if (json.containsKey('type'))
302302
this.type = OSNotificationActionType.values[json['type'] as int];

0 commit comments

Comments
 (0)