我想这样.我使用FCM推送通知.消息到达,但不像抬头.它只出现在状态栏.我做错了什么,还是我必须做别的事情?
6za6bjd01#
你想在通知栏中显示你的应用通知吗?如果是,你应该试试这个软件包flutter_local_notifications: ^16.3.0as you can show on top of image
flutter_local_notifications: ^16.3.0
cfh9epnr2#
要在Flutter中创建通知,您需要awesome_notifications包在您的主.dart文件中:
AwesomeNotifications().initialize( // set the icon to null if you want to use the default app icon null, [ NotificationChannel( channelGroupKey: 'channel_group_key', channelKey: 'channel_key', channelName: 'channel_name', channelDescription: 'channel_description', importance: NotificationImportance.Max, ) ], debug: true,);
AwesomeNotifications().initialize(
// set the icon to null if you want to use the default app icon
null,
[
NotificationChannel(
channelGroupKey: 'channel_group_key',
channelKey: 'channel_key',
channelName: 'channel_name',
channelDescription: 'channel_description',
importance: NotificationImportance.Max,
)
],
debug: true,
);
字符串仅限Android初始化:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example"> <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" /> <application> ... <activity android:name=".MainActivity" android:showOnLockScreen="true" android:showWhenLocked="true" android:turnScreenOn="true"> ... </activity> ... </application></manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example">
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<application>
...
<activity
android:name=".MainActivity"
android:showOnLockScreen="true"
android:showWhenLocked="true"
android:turnScreenOn="true">
</activity>
</application>
</manifest>
型注意事项:在iOS上,你需要请求通知权限。在Android 11上,你需要请求fullScreenIntent。下面是代码(将其放入initState()或其他):
AwesomeNotifications().isNotificationAllowed().then( (isAllowed) { //It would be more appropriate if you can show your own dialog //to the user before requesting the notifications permissons. if (!isAllowed) { AwesomeNotifications().requestPermissionToSendNotifications( permissions: [ NotificationPermission.Alert, NotificationPermission.Sound, NotificationPermission.Badge, NotificationPermission.Vibration, NotificationPermission.Light, NotificationPermission.FullScreenIntent, ], ); } });
AwesomeNotifications().isNotificationAllowed().then(
(isAllowed) {
//It would be more appropriate if you can show your own dialog
//to the user before requesting the notifications permissons.
if (!isAllowed) {
AwesomeNotifications().requestPermissionToSendNotifications(
permissions: [
NotificationPermission.Alert,
NotificationPermission.Sound,
NotificationPermission.Badge,
NotificationPermission.Vibration,
NotificationPermission.Light,
NotificationPermission.FullScreenIntent,
}
型以及如何创建通知,把它每当你需要消防通知:
AwesomeNotifications().createNotification( content: NotificationContent( id: 10, channelKey: 'channel key' //Same as above in initilize, title: title, body: body, wakeUpScreen: true, fullScreenIntent: true, criticalAlert: true, //Other parameters ),);
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 10,
channelKey: 'channel key' //Same as above in initilize,
title: title,
body: body,
wakeUpScreen: true,
fullScreenIntent: true,
criticalAlert: true,
//Other parameters
),
型
2条答案
按热度按时间6za6bjd01#
你想在通知栏中显示你的应用通知吗?如果是,你应该试试这个软件包
flutter_local_notifications: ^16.3.0
as you can show on top of image
cfh9epnr2#
要在Flutter中创建通知,您需要awesome_notifications包
在您的主.dart文件中:
字符串
仅限Android初始化:
型
注意事项:在iOS上,你需要请求通知权限。在Android 11上,你需要请求fullScreenIntent。下面是代码(将其放入initState()或其他):
型
以及如何创建通知,把它每当你需要消防通知:
型