Skip to content

[question]: How to Capture silent notification data #985

Description

@sunilsinghchaudhary00

How can we help?

I am trying to capture the silent notification data but unable to do that showing data in log but its onesignal data not my logs
i am getting silent notif data in backgorund onesignal logs

D/OneSignal(28679): [DefaultDispatcher-worker-1] Saving Notification id=d4eed-9291-4a21-aa66-bf11fb6e5eba
D/OneSignal(28679): [DefaultDispatcher-worker-1] Notification saved values: full_data={"google.delivered_priority":"normal","google.sent_time":1735539186317,"google.ttl":2419200,"google.original_priority":"normal","custom":"{"i":"d4eed-9291-4a21-6-bf11fb6e5eba","a":{"body":"{\"description\":\"Testing Silent Notification\"}","click_action":"FLUTTER_NOTIFICATION_CLICK","description":"Testing Silent Notification","title":"Testing Silent Notification"}}","google.product_id":11181503,"from":"38108206621","google.message_id":"0:173553915688%00ae9cb1f9fd7ecd","google.c.sender.id":"381086206621"}

my code is

void initonesignal() {
OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
OneSignal.Debug.setAlertLevel(OSLogLevel.none);
OneSignal.consentRequired(false);
OneSignal.initialize("40a574c6-b53f-4277-98bb-e42e96a6028f");
OneSignal.User.pushSubscription.addObserver((state) async {
global.onesignalId = OneSignal.User.pushSubscription.id;
print("Opted Push Subscription Id ${global.onesignalId}");
print("Opt Subscription Token ${OneSignal.User.pushSubscription.token}");
await saveOneSignalId(global.onesignalId!);
});

OneSignal.Notifications.addPermissionObserver((state) {
  log("Has permission $state");
});

OneSignal.Notifications.addClickListener((event) {
  try {
    onSelectNotification(event.notification.additionalData);
  } catch (e) {
    log('Failed to decode handleNotificationData: $e');
  }
});
OneSignal.Notifications.addForegroundWillDisplayListener((event) {
  event.preventDefault();
  event.notification.display();
  log('capture onesignal ${event.notification.additionalData} ');
  showForegroundNotification(event.notification.additionalData);
});

}

custom sound working finee
normal default sound working fine capture data in logs fine
but in silent notif no data is capture in logs pls help anybody have any idea how to do that really helpfull

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions