Reputation: 2837
I am using the example from flutter_local_notifications version v18.0.1: https://github.com/MaikuB/flutter_local_notifications/tree/flutter_local_notifications-v18.0.1/flutter_local_notifications/example
When I change the channel ID and channel name from 'repeating channel id'
, 'repeating channel name'
to 'your channel id'
, 'your channel name'
, the message is displayed. However, when using the original channel ID('repeating channel id'
) and name('repeating channel name'
), the notification only shows a small icon without the message(When I pull down from the top of the device, I can view the details of the notification.).
Here is the code where the message is not being displayed: https://github.com/MaikuB/flutter_local_notifications/blob/flutter_local_notifications-v18.0.1/flutter_local_notifications/example/lib/main.dart#L1867
Future<void> _repeatNotification() async { const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( 'repeating channel id', 'repeating channel name', channelDescription: 'repeating description'); const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails); await flutterLocalNotificationsPlugin.periodicallyShow( id++, 'repeating title', 'repeating body', RepeatInterval.everyMinute, notificationDetails, androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, ); }
After changing to 'your channel id'
, 'your channel name'
, the message is displayed:
Future<void> _repeatNotification() async {
const AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails(
'your channel id', 'your channel name', // Change ID and name
channelDescription: 'repeating description');
const NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);
await flutterLocalNotificationsPlugin.periodicallyShow(
id++,
'repeating title',
'repeating body',
RepeatInterval.everyMinute,
notificationDetails,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
);
}
I searched for occurrences of 'your channel id'
in the code but couldn't find any specific conditions for displaying the notification message.
I also checked the Android documentation on channels: https://developer.android.com/develop/ui/views/notifications/channels
but I still don't understand why changing the channel ID and name made the message appear.
The reason I changed it to 'your channel id', 'your channel name' is that it was used in other parts of the code where the message was successfully displayed: https://github.com/MaikuB/flutter_local_notifications/blob/flutter_local_notifications-v18.0.1/flutter_local_notifications/example/lib/main.dart#L1052
Future<void> _showNotification() async { const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails('your channel id', 'your channel name', channelDescription: 'your channel description', importance: Importance.max, priority: Priority.high, ticker: 'ticker'); const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'plain title', 'plain body', notificationDetails, payload: 'item x'); }
So, I simply referenced the code where the message was displayed, I don’t fully understand why it works. I would like to know the underlying mechanism.
At first, I thought that importance: Importance.max
and priority: Priority.high
might be related, so I tried various things. However, in the end, the factor that mattered was the channel ID and channel name.
Upvotes: 1
Views: 73