Skip to content

Commit

Permalink
[flutter_local_notifications] fixes parsing of callback handles for n…
Browse files Browse the repository at this point in the history
…otification actions on Android (#1798)

* fixes parsing of callback handles for notification actions on Android

* Google Java Format

Co-authored-by: github-actions <>
  • Loading branch information
MaikuB committed Nov 21, 2022
1 parent 35cf591 commit d65e618
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
4 changes: 4 additions & 0 deletions flutter_local_notifications/CHANGELOG.md
@@ -1,3 +1,7 @@
# [12.0.4]

* Fixed issue [1796](https://github.com/MaikuB/flutter_local_notifications/issues/1796) where a `java.lang.ClassCastException` may be thrown on some Android devices when the `onDidReceiveBackgroundNotificationResponse` has been specified when calling `initialize()`

# [12.0.3+1]

* Updated Kotlin version used in example app
Expand Down
Expand Up @@ -64,6 +64,7 @@
import com.dexterous.flutterlocalnotifications.models.styles.MessagingStyleInformation;
import com.dexterous.flutterlocalnotifications.models.styles.StyleInformation;
import com.dexterous.flutterlocalnotifications.utils.BooleanUtils;
import com.dexterous.flutterlocalnotifications.utils.LongUtils;
import com.dexterous.flutterlocalnotifications.utils.StringUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -1485,8 +1486,8 @@ private void initialize(MethodCall call, Result result) {
return;
}

Long dispatcherHandle = call.argument(DISPATCHER_HANDLE);
Long callbackHandle = call.argument(CALLBACK_HANDLE);
Long dispatcherHandle = LongUtils.parseLong(call.argument(DISPATCHER_HANDLE));
Long callbackHandle = LongUtils.parseLong(call.argument(CALLBACK_HANDLE));
if (dispatcherHandle != null && callbackHandle != null) {
new IsolatePreferences(applicationContext).saveCallbackKeys(dispatcherHandle, callbackHandle);
}
Expand Down
Expand Up @@ -13,6 +13,8 @@
import com.dexterous.flutterlocalnotifications.models.styles.InboxStyleInformation;
import com.dexterous.flutterlocalnotifications.models.styles.MessagingStyleInformation;
import com.dexterous.flutterlocalnotifications.models.styles.StyleInformation;
import com.dexterous.flutterlocalnotifications.utils.LongUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -250,7 +252,7 @@ private static void readPlatformSpecifics(
readGroupingInformation(notificationDetails, platformChannelSpecifics);
notificationDetails.onlyAlertOnce = (Boolean) platformChannelSpecifics.get(ONLY_ALERT_ONCE);
notificationDetails.showWhen = (Boolean) platformChannelSpecifics.get(SHOW_WHEN);
notificationDetails.when = parseLong(platformChannelSpecifics.get(WHEN));
notificationDetails.when = LongUtils.parseLong(platformChannelSpecifics.get(WHEN));
notificationDetails.usesChronometer =
(Boolean) platformChannelSpecifics.get(USES_CHRONOMETER);
readProgressInformation(notificationDetails, platformChannelSpecifics);
Expand All @@ -261,7 +263,8 @@ private static void readPlatformSpecifics(
notificationDetails.ticker = (String) platformChannelSpecifics.get(TICKER);
notificationDetails.visibility = (Integer) platformChannelSpecifics.get(VISIBILITY);
notificationDetails.allowWhileIdle = (Boolean) platformChannelSpecifics.get(ALLOW_WHILE_IDLE);
notificationDetails.timeoutAfter = parseLong(platformChannelSpecifics.get(TIMEOUT_AFTER));
notificationDetails.timeoutAfter =
LongUtils.parseLong(platformChannelSpecifics.get(TIMEOUT_AFTER));
notificationDetails.category = (String) platformChannelSpecifics.get(CATEGORY);
notificationDetails.fullScreenIntent =
(Boolean) platformChannelSpecifics.get((FULL_SCREEN_INTENT));
Expand Down Expand Up @@ -289,16 +292,6 @@ private static void readPlatformSpecifics(
}
}

private static Long parseLong(Object object) {
if (object instanceof Integer) {
return ((Integer) object).longValue();
}
if (object instanceof Long) {
return (Long) object;
}
return null;
}

private static void readProgressInformation(
NotificationDetails notificationDetails, Map<String, Object> platformChannelSpecifics) {
notificationDetails.showProgress = (Boolean) platformChannelSpecifics.get(SHOW_PROGRESS);
Expand Down
@@ -0,0 +1,13 @@
package com.dexterous.flutterlocalnotifications.utils;

public class LongUtils {
public static Long parseLong(Object object) {
if (object instanceof Integer) {
return ((Integer) object).longValue();
}
if (object instanceof Long) {
return (Long) object;
}
return null;
}
}
2 changes: 1 addition & 1 deletion flutter_local_notifications/pubspec.yaml
Expand Up @@ -2,7 +2,7 @@ name: flutter_local_notifications
description: A cross platform plugin for displaying and scheduling local
notifications for Flutter applications with the ability to customise for each
platform.
version: 12.0.3+1
version: 12.0.4
homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications
issue_tracker: https://github.com/MaikuB/flutter_local_notifications/issues

Expand Down

0 comments on commit d65e618

Please sign in to comment.