Bob*_*oby 3 flutter firebase-cloud-messaging
我正在努力实现这样的目标
我正在使用 flutter_local_notifications: ^4.0.1+2 。这是我到目前为止所做的
BigTextStyleInformation bigTextStyleInformation =
BigTextStyleInformation(
payload.notification.body,
htmlFormatBigText: true,
contentTitle: payload.notification.title,
htmlFormatContentTitle: true,
summaryText: payload.data['group_name'].toString(),
htmlFormatSummaryText: true,
);
AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails(
payload.data['group_name'].toString(),
payload.data['group_name'].toString(),
payload.data['group_name'].toString(),
styleInformation: bigTextStyleInformation,
groupKey: payload.data['group_id'].toString(),
setAsGroupSummary: true,
importance: Importance.high,
);
//
NotificationDetails platformChannelSpecifics =
NotificationDetails(android: androidPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.show(
int.parse(payload.data['chat_index']),
payload.notification.title,
payload.notification.body,
platformChannelSpecifics);
Run Code Online (Sandbox Code Playgroud)
这是我发送到 fcm 服务器的内容
{
"registration_ids": [
"dhFLSBuAT3yYC4XoeY7oKf:APA91bGbtYTxmHhua7kewUbR1-PCHlGXyS_WP1jP-vjoLkJ_JoB69fuR8XO8hfmv-_r8VekBIkuFqhhJaHSnlKIJVRaeCAE7Mu682ffZ4MASC2O_v0QR--pQOqY3Anm7Q8liEh4Sg6f9"
],
"notification": {
"body": "Example Message",
"title": "GROUP TEST 1",
"icon": "@drawable/ic_stat_notification_logo",
"sound": "mySound",
"priority": "high",
"show_in_foreground": true,
"click_action": "FLUTTER_NOTIFICATION_CLICK"
},
"data": {
"type": "chat",
"openScreen": true,
"useHomeScreen": true,
"homeScreenBottomIndex": 1,
"group_id": 1,
"group_name": "GROUP 1",
"chat_index": 1
}
}
Run Code Online (Sandbox Code Playgroud)
从上面的脚本我得到这个结果
有什么解决办法吗?
查看Awesome_notifications:0.0.6+9
使用Group Key您可以确定用于以紧凑形式对通知进行分组的公共密钥。
您甚至可以用来Group Sort确定分组内的通知排序顺序
您可以查看本地通知的分组-通知。
以下代码是https://developer.android.com/training/notify-user/group.html上提供的示例的“翻译为 flutter”
代码 -
const String groupKey = 'com.android.example.WORK_EMAIL';
const String groupChannelId = 'grouped channel id';
const String groupChannelName = 'grouped channel name';
const String groupChannelDescription = 'grouped channel description';
// example based on https://developer.android.com/training/notify-user/group.html
const AndroidNotificationDetails firstNotificationAndroidSpecifics =
AndroidNotificationDetails(
groupChannelId, groupChannelName, groupChannelDescription,
importance: Importance.max,
priority: Priority.high,
groupKey: groupKey);
const NotificationDetails firstNotificationPlatformSpecifics =
NotificationDetails(android: firstNotificationAndroidSpecifics);
await flutterLocalNotificationsPlugin.show(1, 'Alex Faarborg',
'You will not believe...', firstNotificationPlatformSpecifics);
const AndroidNotificationDetails secondNotificationAndroidSpecifics =
AndroidNotificationDetails(
groupChannelId, groupChannelName, groupChannelDescription,
importance: Importance.max,
priority: Priority.high,
groupKey: groupKey);
const NotificationDetails secondNotificationPlatformSpecifics =
NotificationDetails(android: secondNotificationAndroidSpecifics);
await flutterLocalNotificationsPlugin.show(
2,
'Jeff Chang',
'Please join us to celebrate the...',
secondNotificationPlatformSpecifics);
// Create the summary notification to support older devices that pre-date
/// Android 7.0 (API level 24).
///
/// Recommended to create this regardless as the behaviour may vary as
/// mentioned in https://developer.android.com/training/notify-user/group
const List<String> lines = <String>[
'Alex Faarborg Check this out',
'Jeff Chang Launch Party'
];
const InboxStyleInformation inboxStyleInformation = InboxStyleInformation(
lines,
contentTitle: '2 messages',
summaryText: 'janedoe@example.com');
const AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails(
groupChannelId, groupChannelName, groupChannelDescription,
styleInformation: inboxStyleInformation,
groupKey: groupKey,
setAsGroupSummary: true);
const NotificationDetails platformChannelSpecifics =
NotificationDetails(android: androidPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.show(
3, 'Attention', 'Two messages', platformChannelSpecifics);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2410 次 |
| 最近记录: |