'Problem with Awesome Notifications ActionButtonType.InputField (Flutter)
I am implementing quick reply in my notification using Awesome Notifications InputField in Flutter. Everything works fine, the notification is sent but after typing the reply text and hitting the send button, my app is opened in foreground and the phone suddenly locks itself and the same notification is sent again. The following Error is displayed in the console:
E/AndroidRuntime(11446): FATAL EXCEPTION: main
E/AndroidRuntime(11446): Process: com.android.systemui, PID: 11446
E/AndroidRuntime(11446): java.lang.ClassCastException: android.os.Parcelable[] cannot be cast to android.app.RemoteInputHistoryItem[]
E/AndroidRuntime(11446): at com.android.systemui.statusbar.notification.collection.NotificationEntry.isLastMessageFromReply(NotificationEntry.java:572)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.phone.NotificationIconAreaController.shouldShowNotificationIcon(NotificationIconAreaController.java:329)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.phone.NotificationIconAreaController.updateIconsForLayout(NotificationIconAreaController.java:448)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.phone.NotificationIconAreaController.updateStatusBarIcons(NotificationIconAreaController.java:378)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.phone.NotificationIconAreaController.updateNotificationIcons(NotificationIconAreaController.java:356)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.updateIconAreaViews(NotificationStackScrollLayout.java:6045)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.phone.NotificationPanelViewController.updateNotificationViews(NotificationPanelViewController.java:3115)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.phone.MiuiNotificationPanelViewController.updateNotificationViews(MiuiNotificationPanelViewController.kt:1051)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.phone.StatusBarNotificationPresenter.updateNotificationViews(StatusBarNotificationPresenter.java:355)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.notification.NotificationEntryManager.updateNotifications(NotificationEntryManager.java:718)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.notification.NotificationEntryManager.updateNotificationInternal(NotificationEntryManager.java:686)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.notification.NotificationEntryManager.updateNotification(NotificationEntryManager.java:705)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.notification.NotificationEntryManager$2.onNotificationPosted(NotificationEntryManager.java:378)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.NotificationListener.lambda$onNotificationPosted$1(NotificationListener.java:134)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.NotificationListener.lambda$onNotificationPosted$1$NotificationListener(Unknown Source:0)
E/AndroidRuntime(11446): at com.android.systemui.statusbar.-$$Lambda$NotificationListener$NvFmU0XrVPuc5pizHcri9I0apkw.run(Unknown Source:6)
E/AndroidRuntime(11446): at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime(11446): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(11446): at android.os.Looper.loop(Looper.java:236)
E/AndroidRuntime(11446): at android.app.ActivityThread.main(ActivityThread.java:8037)
E/AndroidRuntime(11446): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11446): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
E/AndroidRuntime(11446): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
W/FileUtils( 9775): Slow Operation: fsync took 138ms procState=2
My Code:
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
print('Handling a background message: ${message.messageId}');
print("MSG:" + message.toString());
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: message.data.hashCode,
channelKey: 'basic_channel_two',
title: message.data["title"],
body: message.data["body"],
),
actionButtons: [
NotificationActionButton(
key: 'Reply_Msg',
label: 'Reply',
autoDismissible: true,
buttonType: ActionButtonType.InputField,
)
],
);
}
void initNotification() async {
AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
print("isAllowed: " + isAllowed.toString());
if (!isAllowed) {
AwesomeNotifications().requestPermissionToSendNotifications();
}
});
AwesomeNotifications().actionStream.listen((event) {
if (event.buttonKeyPressed == 'Reply_Msg') {
print(event.buttonKeyPressed);
print(event.toMap().toString());
}
});
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
WidgetsFlutterBinding.ensureInitialized();
AwesomeNotifications().initialize(
'resource://mipmap/ic_launcher',
[
NotificationChannel(
channelGroupKey: 'basic_tests_two',
channelKey: 'basic_channel_two',
channelName: 'Basic Notifications',
channelDescription: 'Notification channel for basic tests',
defaultColor: Color(0xFF9D50DD),
importance: NotificationImportance.Max,
channelShowBadge: true,
enableVibration: true,
playSound: true,
defaultPrivacy: NotificationPrivacy.Private,
soundSource: 'resource://raw/alert',
groupKey: 'MyApp',
),
],
channelGroups: [
NotificationChannelGroup(
channelGroupkey: 'basic_tests_two',
channelGroupName: 'Basic Tests'),
],
debug: true);
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: message.data.hashCode,
channelKey: 'basic_channel_two',
title: message.data["title"],
body: message.data["body"],
),
actionButtons: [
NotificationActionButton(
key: 'Reply_Msg',
label: 'Reply',
autoDismissible: true,
buttonType: ActionButtonType.InputField,
),
],
);
});
}
Also, is there any way to not "Bring the app to foreground" after pressing the send button in Awesome Notification InputField?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
