flutter_notification_channel
안드로이드에서 알림 채널을 설정하기 위한 플러그인
firebase_messaging 버전 7.0.3(현재) 및 이하 버전은 알림 채널을 설정할 수 없기 때문에 알림이 소리를 내지 않거나 잠금 화면에 표시되지 않거나 튀어나오지 않는 등의 문제가 발생합니다. 이 플러그인은 Android에서 다른 구성으로 알림 채널을 생성하기 위한 목적만을 가지고 있습니다. 이후 firebase_messaging과 함께 사용할 수 있습니다.
{"sdk":"flutter"}^2.1.8{"sdk":"flutter"}아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
https://pub.dev/packages/flutter_notification_channel
This plugin is made to register notification channels with custom configurations on Android. For more details read this https://developer.android.com/training/notify-user/channels Why is it necessary? E.g. firebase_messaging version 7.0.3 (current) and lower do not allow to set up a notification channel, thus notifications don't play any sounds or do not display on locked screen, or don't bubble and so on. This plugin is made merely for the purpose of creation a notification channel with custom configurations on Android. The channels then can be used along with firebase_messaging.
Simply call it like this
var result = await FlutterNotificationChannel().registerNotificationChannel(
description: 'Your channel description',
id: 'your_channel_id',
importance: NotificationImportance.IMPORTANCE_HIGH,
name: 'Your channel name',
visibility: NotificationVisibility.VISIBILITY_PUBLIC,
allowBubbles: true,
enableVibration: true,
enableSound: true,
showBadge: true,
);
print(result);
The plugin supports the following notification importance levels:
NotificationImportance.IMPORTANCE_MIN (1): Minimal importance, might not be shownNotificationImportance.IMPORTANCE_LOW (2): Low importance, shows in shade and potentially status bar but not audibly intrusiveNotificationImportance.IMPORTANCE_DEFAULT (3): Default importance, shows everywhere and makes noise but doesn't visually intrudeNotificationImportance.IMPORTANCE_HIGH (4): Higher importance, shows everywhere, makes noise and peeks, may use full screen intentsNotificationImportance.IMPORTANCE_MAX (5): Maximum importance, most intrusive level, should be used sparingly for critical notifications onlyFor critical notifications that require immediate user attention:
var result = await FlutterNotificationChannel().registerNotificationChannel(
description: 'Critical system alerts',
id: 'critical_channel_id',
importance: NotificationImportance.IMPORTANCE_MAX,
name: 'Critical Alerts',
visibility: NotificationVisibility.VISIBILITY_PUBLIC,
allowBubbles: true,
enableVibration: true,
enableSound: true,
showBadge: true,
);
Then, when you send a message to firebase like this, specify your android_channel_id and sound: "default" in order to play a default sound if you set "enableSound" in plugin. If you don't do this, the sound wont play at all on android 9 (I have no idea why)
{
"notification": {
"title": "Your message title",
"body": "Your message body",
"android_channel_id": "your_channel_id",
"sound": "default"
},
"data": {
"click_action" : "FLUTTER_NOTIFICATION_CLICK",
},
"priority": "high",
"content_available": true,
"to": "YOUR_FIREBASE_PUSH_TOKEN_GOES_HERE"
}