[英]Flutter: How to define notification channel in firebase_messaging package?
I am sending this json to cloud messaging (with proper headers) and want to get notification on my device, but it does not appear on my phone.我正在将此 json 发送到云消息(带有正确的标头)并希望在我的设备上收到通知,但它没有出现在我的手机上。 I think that maybe i am missing channel id initialization for Android?
我想也许我缺少 Android 的频道 ID 初始化?
*Additional info *附加信息
{
"to" : "my device token",
"mutable_content" : true,
"content_available": true,
"data" : {
"content": {
"id": 100,
"channelKey": "basic_channel",
"title": "Huston!\nThe eagle has landed!",
"body": "A small step for a man, but a giant leap to Flutter's community!",
"notificationLayout": "BigPicture",
"largeIcon": "https://media.fstatic.com/kdNpUx4VBicwDuRBnhBrNmVsaKU=/full-fit-in/290x478/media/artists/avatar/2013/08/neil-i-armstrong_a39978.jpeg",
"bigPicture": "https://www.dw.com/image/49519617_303.jpg",
"showWhen": true,
"autoCancel": true,
"privacy": "Private"
},
"actionButtons": [
{
"key": "REPLY",
"label": "Reply",
"autoCancel": true,
"buttonType": "InputField"
},
{
"key": "ARCHIVE",
"label": "Archive",
"autoCancel": true
}
]
}
}
In order to define a notification channel you have to go to your AndroidManifest.xml
and within the application component add this meta:为了定义通知通道,您必须将 go 到您的
AndroidManifest.xml
并在应用程序组件中添加此元:
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
then in your strings.xml file put the channel id like this:然后在您的 strings.xml 文件中输入频道 ID,如下所示:
<string name='default_notification_channel_id'>Channel ID</string>
After doing this, you can define your channel id in the FCM Console.完成此操作后,您可以在 FCM 控制台中定义您的频道 ID。
As simple as this.就这么简单。 Just put your android channel name here below and it works with a charm:
只需在下面输入您的 android 频道名称,它就会发挥作用:
"notification": {
"body": "Test notification",
"title": "Test Test Test",
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"sound": "your_custom_sound"
"android_channel_id": "channel_id_youcreated",
},
'to':
"",
},
Sound file name is not necessary in the above given notification payload if you assigned that sound to your notification channel thru MainActivity.kt or java file.如果您通过 MainActivity.kt 或 java 文件将该声音分配给您的通知通道,则上述通知有效负载中不需要声音文件名。 However, it is necessary for older Android versions as they will use the sound file directly.
但是,对于较旧的 Android 版本是必需的,因为它们将直接使用声音文件。 Put your file inside res/raw folder.
将文件放在 res/raw 文件夹中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.