简体   繁体   中英

Flutter - OneSignal notification

I implement OneSignal device to device notification on my flutter project and it workes on android device.

Future<Response> sendNotification(List<String> tokenIdList, String heading, String contents) async{

    return await post(
      Uri.parse('https://onesignal.com/api/v1/notifications'),
      headers: <String, String>{
        'Content-Type': 'application/json; charset=UTF-8',
      },
      body: jsonEncode(<String, dynamic>
      {
        "app_id": kAppId,

        "include_player_ids": tokenIdList,

        "android_accent_color":"FF9976D2",

        "small_icon":"ic_stat_onesignal_default",

        "large_icon":"https://www.filepicker.io/api/file/zPloHSmnQsix82nlj9Aj?filename=name.jpg",

        "headings": {"en": heading},

        "contents": {"en": contents},

      }),
    );
  }

But when the app is closed (killed from the background) the notification works properly, like

在此处输入图像描述

But when the app is running, the same notification looks like an in-app message

在此处输入图像描述

I want notification, not the in-app message. And the way to change the in-app message layout.

OneSignal.shared.consentGranted(true);
OneSignal.shared.setInFocusDisplayType(OSNotificationDisplayType.notification);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM