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

Unresolved reference: addClickListener #2165

Closed
1 task done
fcidev opened this issue Aug 2, 2024 · 1 comment
Closed
1 task done

Unresolved reference: addClickListener #2165

fcidev opened this issue Aug 2, 2024 · 1 comment

Comments

@fcidev
Copy link

fcidev commented Aug 2, 2024

What happened?

I am using the latest version of the Android SDK in kotlin

here is my code

OneSignal.initWithContext(this, ONESIGNAL_APP_ID)
        OneSignal.addClickListener(CustomNotificationClickListener(this))

i have imported the following libraries

import com.onesignal.notifications.INotificationClickEvent
import com.onesignal.notifications.INotificationClickListener

the above Set the custom notification click listener is used for this class file

import com.onesignal.notifications.INotificationClickEvent
import com.onesignal.notifications.INotificationClickListener


/**
 * A custom notification click listener to handle clicks and navigate to the main activity.
 */
class CustomNotificationClickListener(private val context: Context) : INotificationClickListener {

    override fun onClick(event: INotificationClickEvent) {
        // Handle notification click
        val notification = event.notification
        val result = event.result

        // You can use notification or result data if needed
        // For example, you might want to handle specific actions or URLs here

        // Create an intent to start the main activity
        val intent = Intent(context, MainActivity::class.java)
        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK

        // Start the main activity
        context.startActivity(intent)
    }
}

can anyone help me fix this issue, I went through documentation i didn't find anything for custom notification opened handling for v5 SDK

Steps to reproduce?

create a custom class and use this line 
OneSignal.addClickListener(CustomNotificationClickListener(this))

What did you expect to happen?

I wanted to open the main activity when notification was clicked

OneSignal Android SDK version

release 5.1.8

Android version

14, 13, 12, 11, 10

Specific Android models

No response

Relevant log output

Unresolved reference: addClickListener

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jinliu9508
Copy link
Contributor

@fcidev Can you try OneSignal.Notifications.addClickListener(CustomNotificationClickListener(this))?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants