如何启用;“将通知显示为弹出窗口”;默认情况下在android设备上?

如何启用;“将通知显示为弹出窗口”;默认情况下在android设备上?,android,flutter,push-notification,firebase-cloud-messaging,android-notifications,Android,Flutter,Push Notification,Firebase Cloud Messaging,Android Notifications,我正在用flifter开发一个食品配送应用程序。我最近实现了flatter_local_通知,该通知运行良好。但有一个问题是,默认情况下,通知不会显示为弹出窗口。默认情况下,“显示为弹出窗口”选项在通知设置中处于禁用状态 安装应用程序时,默认情况下是否启用“显示为弹出窗口”选项 这是我的通知配置代码: void registerNotification() { // This function registers the user for recieving push notificat

我正在用flifter开发一个食品配送应用程序。我最近实现了flatter_local_通知,该通知运行良好。但有一个问题是,默认情况下,通知不会显示为弹出窗口。默认情况下,“显示为弹出窗口”选项在通知设置中处于禁用状态

安装应用程序时,默认情况下是否启用“显示为弹出窗口”选项

这是我的通知配置代码:

void registerNotification() {
    // This function registers the user for recieving push notifications.
    // After registering the user, it creates a new field inside 'userForChat' Database
    // The field is called : 'pushToken' which is later used on to configure Firebase Automatic Cloud Messaging
    firebaseMessaging.requestNotificationPermissions();

    firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) {
        print('onMessage: $message');
        Platform.isAndroid
            ? showNotification(message['notification'])
            : showNotification(message['aps']['alert']);
        return;
      },
      onResume: (Map<String, dynamic> message) {
        print('onResume: $message');
        return;
      },
      onLaunch: (Map<String, dynamic> message) {
        print('onLaunch: $message');
        return;
      },
    );

    // Token for Firebase Messaging
    firebaseMessaging.getToken().then((token) {
      print('token: $token');

      Firestore.instance
          .collection('usersForChat')
          .document(currentUserId)
          .updateData(
              {'pushToken': token}); //Sets the firebase Token into the database
    }).catchError((onError) {
      setState(() {});
    });
  }

  void configLocalNotification() {

    var initializationSettingsAndroid = AndroidInitializationSettings(
        'mipmap/ic_launcher'); 
    var initializationSettingsIOS = IOSInitializationSettings();
    var initializationSettings = InitializationSettings(
        initializationSettingsAndroid, initializationSettingsIOS);
    flutterLocalNotificationsPlugin.initialize(initializationSettings);
  }

  void showNotification(message) async {
    // This function takes the notfication message as input triggers the notification to show the message.
    // The input is in a json format so you have to decode the json with dart:convert.

    // IMPORTANT: Specify the Application package name according to the OS.
    //For Android, Use the android app package name from firebase
    //For iOS, Use the iOS app package name from firebase

    var androidPlatformChannelSpecifics = AndroidNotificationDetails(
      // add your apps package name for each OS(Android:iOS)
      Platform.isAndroid
          ? 'com.jexmovers.app' //Update the package name to your app's package names
          : 'com.jexmovers.ios', //Update the package name to your app's package names
      'JexMovers Chat',
      'App that lets you contact with your food delivery person',
      playSound: true,
      enableVibration: true,
      importance: Importance.Max,
      priority: Priority.Max,
      visibility: NotificationVisibility.Public,
      enableLights: true,
    );

    var iOSPlatformChannelSpecifics = IOSNotificationDetails();
    var platformChannelSpecifics = NotificationDetails(
        androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);

    print(message);

    print(message['body'].toString());
    print(json.encode(message));

    await flutterLocalNotificationsPlugin.show(
      0,
      message['title'].toString(),
      message['body'].toString(),
      platformChannelSpecifics,
      payload: json.encode(message),
    );
  }
无效注册表通知(){
//此函数注册用户以接收推送通知。
//注册用户后,它会在“userForChat”数据库中创建一个新字段
//该字段名为:“pushToken”,稍后用于配置Firebase自动云消息传递
firebaseMessaging.requestNotificationPermissions();
firebaseMessaging.configure(
onMessage:(映射消息){
打印('onMessage:$message');
平顶板蓝根
?showNotification(消息['notification'])
:showNotification(消息['aps']['alert']);
返回;
},
onResume:(映射消息){
打印('onResume:$message');
返回;
},
onLaunch:(映射消息){
打印('onLaunch:$message');
返回;
},
);
//Firebase消息传递令牌
firebaseMessaging.getToken().then((令牌){
打印('token:$token');
Firestore.instance
.collection('usersForChat')
.document(currentUserId)
更新数据(
{'pushToken':token});//将firebase令牌设置到数据库中
}).catchError((onError){
setState((){});
});
}
void configLocalNotification(){
var initializationSettingsAndroid=AndroidInitializationSettings(
“mipmap/ic_启动器”);
var initializationSettingsIOS=IOSInitializationSettings();
var initializationSettings=初始化设置(
初始化设置和ROID,初始化设置SIOS);
flatterLocalNotificationsPlugin.initialize(初始化设置);
}
无效显示通知(消息)异步{
//此函数将notification消息作为输入,触发显示消息的通知。
//输入为json格式,因此必须使用dart:convert解码json。
//要点:根据操作系统指定应用程序包名称。
//对于Android,请使用firebase提供的Android应用程序包名称
//对于iOS,请使用firebase提供的iOS应用程序包名称
var androidPlatformChannelSpecifics=AndroidNotificationDetails(
//为每个操作系统添加应用程序包名称(Android:iOS)
平顶板蓝根
?'com.jexmovers.app'//将程序包名称更新为应用程序的程序包名称
:'com.jexmovers.ios',//将包名更新为应用程序的包名
“JexMovers聊天室”,
“让您与食品配送人员联系的应用程序”,
playSound:没错,
使能振动:正确,
重要性:重要性,马克斯,
优先级:优先级,最大值,
可见性:NotificationVisibility.Public,
使能灯光:正确,
);
var iOSPlatformChannelSpecifics=ioNotificationDetails();
var platformChannelSpecifics=通知详细信息(
androidPlatformChannelSpecifics、iOSPlatformChannelSpecifics);
打印(信息);
打印(消息['body'].toString());
打印(json.encode(消息));
等待本地通知。显示(
0,
消息['title'].toString(),
消息['body'].toString(),
平台通道细节,
有效负载:json.encode(消息),
);
}

您找到解决此问题的方法了吗?您找到解决此问题的方法了吗?