Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method setNotificationWillShowInForegroundHandler not triggered on Android #506

Closed
marcoberetta96 opened this issue Nov 13, 2021 · 4 comments

Comments

@marcoberetta96
Copy link

marcoberetta96 commented Nov 13, 2021

Description:
The method setNotificationWillShowInForegroundHandler is not triggered for Android when app is active and when receiving a notification like this one.

[
    'contents' => [
        'en' => 'Notification message',
        'title' => 'test',
        'content' => 'hello',
    ],
    'app_id' => self::APP_ID,
    'data' => ['foo' => 'bar'],
    'include_player_ids' => self::PLAYER_IDS,
]

On iOS, the method is triggered and I can decide not to show the notification.
On Android the method is not triggered at all.

Environment

  1. What version of the OneSignal Flutter SDK are you using? onesignal_flutter: ^3.2.5
  2. How did you add the SDK to your project? Testing the example

Steps to Reproduce Issue:
Just use the example of this project and set the following.

OneSignal.shared.setNotificationWillShowInForegroundHandler((OSNotificationReceivedEvent event) {
      print('setNotificationWillShowInForegroundHandler: $event');
      setState(() => _debugLabelString = "Foreground notification: \n${event.notification.jsonRepresentation().replaceAll("\\n", "\n")}");
     event.complete(null); // Display Notification, send null to not display
    });

Logs when receiving notification on Android

V/OneSignal( 5424): initWithContext called with: android.app.ReceiverRestrictedContext@fc162bb
V/OneSignal( 5424): Starting OneSignal initialization!
V/OneSignal( 5424): No class found, not setting up OSRemoteNotificationReceivedHandler
D/OneSignal( 5424): OneSignal SDK initialization already completed.
D/OneSignal( 5424): OSNotificationWorkManager enqueueing notification work with notificationId: 5b1f182e-374f-4f41-88e8-46f12b288d11 and jsonPayload: {"google.delivered_priority":"normal","google.sent_time":1636813840323,"google.ttl":259200,"google.original_priority":"normal","custom":"{\"a\":{\"foo\":\"bar\"},\"i\":\"5b1f182e-374f-4f41-88e8-46f12b288d11\"}","from":"198414532777","alert":"Notification message","google.message_id":"0:1636813840336424%e1d06f09f9fd7ecd","google.c.sender.id":"198414532777"}
D/OneSignal( 5424): NotificationWorker running doWork with data: Data {json_payload : {"google.delivered_priority":"normal","google.sent_time":1636813840323,"google.ttl":259200,"google.original_priority":"normal","custom":"{\"a\":{\"foo\":\"bar\"},\"i\":\"5b1f182e-374f-4f41-88e8-46f12b288d11\"}","from":"198414532777","alert":"Notification message","google.message_id":"0:1636813840336424%e1d06f09f9fd7ecd","google.c.sender.id":"198414532777"}, android_notif_id : 0, is_restoring : false, os_bnotification_id : 5b1f182e-374f-4f41-88e8-46f12b288d11, timestamp : 1636813840, }
D/OneSignal( 5424): Running destroyTimeout with runnable: com.onesignal.OSNotificationReceivedEvent$1@f337d58
D/OneSignal( 5424): Running startTimeout with timeout: 25000 and runnable: com.onesignal.OSNotificationReceivedEvent$1@f337d58
W/OneSignal( 5424): remoteNotificationReceivedHandler not setup, displaying normal OneSignal notification
D/OneSignal( 5424): Running destroyTimeout with runnable: com.onesignal.OSNotificationReceivedEvent$1@f337d58
D/OneSignal( 5424): Starting processJobForDisplay opened: false fromBackgroundLogic: true
I/OneSignal( 5424): App is in background, show notification
D/OneSignal( 5424): Saving Notification job: OSNotificationGenerationJob{jsonPayload={"google.delivered_priority":"normal","google.sent_time":1636813840323,"google.ttl":259200,"google.original_priority":"normal","custom":"{\"a\":{\"foo\":\"bar\"},\"i\":\"5b1f182e-374f-4f41-88e8-46f12b288d11\"}","from":"198414532777","alert":"Notification message","google.message_id":"0:1636813840336424%e1d06f09f9fd7ecd","google.c.sender.id":"198414532777"}, isRestoring=false, shownTimeStamp=1636813840, overriddenBodyFromExtender=null, overriddenTitleFromExtender=null, overriddenSound=null, overriddenFlags=null, orgFlags=null, orgSound=null, notification=OSNotification{notificationExtender=null, groupedNotifications=null, androidNotificationId=1270400828, notificationId='5b1f182e-374f-4f41-88e8-46f12b288d11', templateName='', templateId='', title='null', body='Notification message', additionalData={"foo":"bar"}, smallIcon='null', largeIcon='null', bigPicture='null', smallIconAccentColor='null', launchURL='null', sound='null', ledColor='null', lockScreenVisibility=1, groupKey='null', groupMessage='null', actionButtons=null, fromProjectNumber='198414532777', backgroundImageLayout=null, collapseId='null', priority=0, rawPayload='{"google.delivered_priority":"normal","google.sent_time":1636813840323,"google.ttl":259200,"google.original_priority":"normal","custom":"{\"a\":{\"foo\":\"bar\"},\"i\":\"5b1f182e-374f-4f41-88e8-46f12b288d11\"}","from":"198414532777","alert":"Notification message","google.message_id":"0:1636813840336424%e1d06f09f9fd7ecd","google.c.sender.id":"198414532777"}'}}
D/OneSignal( 5424): Notification saved values: full_data={"google.delivered_priority":"normal","google.sent_time":1636813840323,"google.ttl":259200,"google.original_priority":"normal","custom":"{\"a\":{\"foo\":\"bar\"},\"i\":\"5b1f182e-374f-4f41-88e8-46f12b288d11\"}","from":"198414532777","alert":"Notification message","google.message_id":"0:1636813840336424%e1d06f09f9fd7ecd","google.c.sender.id":"198414532777"} notification_id=5b1f182e-374f-4f41-88e8-46f12b288d11 android_notification_id=1270400828 opened=0 expire_time=1637073040 message=Notification message
D/OneSignal( 5424): sendReceiveReceipt disable
D/OneSignal( 5424): Receive receipt ending with success callback completer: androidx.concurrent.futures.CallbackToFutureAdapter$Completer@a706717
D/OneSignal( 5424): OneSignal SessionManager onNotificationReceived notificationId: 5b1f182e-374f-4f41-88e8-46f12b288d11
D/OneSignal( 5424): OneSignal OSChannelTracker for: notification_id saveLastId: 5b1f182e-374f-4f41-88e8-46f12b288d11
D/OneSignal( 5424): OneSignal OSChannelTracker for: notification_id saveLastId with lastChannelObjectsReceived: [{"notification_id":"1aeaf375-afd9-4286-ba64-c5d0364e9c6f","time":1636811236326},{"notification_id":"642bc668-b66b-4d3c-b735-015a80d8d14f","time":1636812593830},{"notification_id":"b5e6105c-5304-40f7-b68c-9c5b8435e127","time":1636813348182},{"notification_id":"9baa97bf-5217-427d-ab04-63ac2ed915c5","time":1636813737131},{"notification_id":"892ac03f-c8e3-4e6f-a627-32ca10fb6ae3","time":1636813821194}]
D/OneSignal( 5424): OneSignal OSChannelTracker for: notification_id with channelObjectToSave: [{"notification_id":"1aeaf375-afd9-4286-ba64-c5d0364e9c6f","time":1636811236326},{"notification_id":"642bc668-b66b-4d3c-b735-015a80d8d14f","time":1636812593830},{"notification_id":"b5e6105c-5304-40f7-b68c-9c5b8435e127","time":1636813348182},{"notification_id":"9baa97bf-5217-427d-ab04-63ac2ed915c5","time":1636813737131},{"notification_id":"892ac03f-c8e3-4e6f-a627-32ca10fb6ae3","time":1636813821194},{"notification_id":"5b1f182e-374f-4f41-88e8-46f12b288d11","time":1636813840100}]
D/OneSignal( 5424): Running destroyTimeout with runnable: com.onesignal.OSNotificationOpenedResult$1@40f1704
I/WM-WorkerWrapper( 5424): Worker result SUCCESS for Work [ id=28e2b88b-b38a-4c7c-8653-81b7235598f9, tags={ com.onesignal.OSNotificationWorkManager$NotificationWorker } ]
D/OneSignal( 5424): Running startTimeout with timeout: 5000 and runnable: com.onesignal.OSNotificationOpenedResult$1@40f1704

Flutter doctor

[✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-x64, locale en-IT)
    • Flutter version 2.5.3
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (4 weeks ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/marco/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Connected device
    • Nexus 5 (mobile)         • 0811ecba00e4b1c8                         • android-arm    • Android 6.0.1 (API 23)
    • Pixel 3a (mobile)        • 948AY0KK49                               • android-arm64  • Android 12 (API 31)
    • iPhone di Marco (mobile) • c14e8b9b123c6219308e3d8b3a25fa8741838244 • ios            • iOS 12.5.5 16H62
@ipapps
Copy link

ipapps commented Nov 15, 2021

Same here

1 similar comment
@massimilianochiodi
Copy link

Same here

@sweatherall
Copy link

sweatherall commented Nov 18, 2021

Same, although I am not using Flutter, but React Native with the react-native-onesignal library (left comment here)

@nan-li
Copy link
Contributor

nan-li commented Nov 18, 2021

Hi @marcoberetta96,

Thank you for reporting.

As other people have submitted details in #509, I will close this for now and follow up on the other issue.

@nan-li nan-li closed this as completed Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants