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

[Bug]: onNotificationReceived() not called #2194

Open
1 task
himadri1266 opened this issue Sep 25, 2024 · 0 comments
Open
1 task

[Bug]: onNotificationReceived() not called #2194

himadri1266 opened this issue Sep 25, 2024 · 0 comments

Comments

@himadri1266
Copy link

himadri1266 commented Sep 25, 2024

What happened?

I am unable to detect notifications in the onNotificationReceived() method of INotificationServiceExtension. This issue occurs whether the app is in the background or foreground. I am using the latest version of the OneSignal SDK, version "5.1.21".

Below is the code I have integrated:

1. build.gradle (app level):
implementation("com.onesignal:OneSignal:5.1.21")

2. AndroidManifest.xml:

<meta-data
     android:name="com.onesignal.NotificationServiceExtension"
     android:value="com.myapp.notification.NotificationService" />

3. NotificationService class:

package com.myapp.notification;

import android.util.Log;

import com.onesignal.notifications.IDisplayableMutableNotification;
import com.onesignal.notifications.INotificationReceivedEvent;
import com.onesignal.notifications.INotificationServiceExtension;

public class NotificationService implements INotificationServiceExtension {
    private String TAG = "NotificationService";

    @Override
    public void onNotificationReceived(INotificationReceivedEvent event) {
        IDisplayableMutableNotification notification = event.getNotification();
        Log.d(TAG, "Title " + notification.getTitle());
        Log.d(TAG, "Body " + notification.getBody());

       event.preventDefault();
    }
}

Steps to reproduce?

1.Install the app on a mobile device.
2.Enable the notification service.
3.Send a test notification from the OneSignal dashboard.
4.Check the onNotificationReceived() method.

What did you expect to happen?

Whenever a notification arrives on the mobile device, the onNotificationReceived() method will be executed and will handle the API call from within that method.

OneSignal Android SDK version

5.1.21

Android version

15, 14, 13, 12

Specific Android models

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
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

1 participant