Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_local_notifications] fixes parsing of callback handles for notification actions on Android #1798

Merged
merged 2 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions flutter_local_notifications/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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