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

[question]: cannot resolve method 'setNotificationOpenedHandler' #1816

Closed
1 task done
irinapopova124 opened this issue Aug 25, 2023 · 4 comments
Closed
1 task done

Comments

@irinapopova124
Copy link

irinapopova124 commented Aug 25, 2023

Please help. OneSignal implemented on Gradle, Import Added. But still not recognizing the method..

     plugins {
         id 'com.android.application'
          // Add the Google services Gradle plugin
         id 'com.google.gms.google-services'
     }

     android {
         namespace 'com.irina.testapp'
         compileSdk 33

         defaultConfig {
             applicationId "com.dynamicview.slotterbaik"
             minSdk 28
             targetSdk 33
             versionCode 2
             versionName "1.0"
             testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
         }

         buildTypes {
             release {
                 minifyEnabled false
                 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
             }
         }
         compileOptions {
             sourceCompatibility JavaVersion.VERSION_1_8
             targetCompatibility JavaVersion.VERSION_1_8
         }
     }

     dependencies {

    i     mplementation 'androidx.appcompat:appcompat:1.4.1'
         implementation 'com.google.android.material:material:1.5.0'
         implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
         testImplementation 'junit:junit:4.13.2'
         androidTestImplementation 'androidx.test.ext:junit:1.1.3'
         androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

         // Import the Firebase BoM
        implementation platform('com.google.firebase:firebase-bom:32.2.2')


        // TODO: Add the dependencies for Firebase products you want to use

        //Import OneSignal
        implementation 'com.onesignal:OneSignal:[5.0.0, 5.99.99]'
    }

in MainActivity

cannot resolve method 'setNotificationOpenedHandler'
import com.onesignal.OneSignal;

OneSignal.setNotificationOpenedHandler(new OneSignal.OSNotificationOpenedHandler() {
            @Override
            public void notificationOpened(OSNotificationOpenedResult result) {
                JSONObject data = result.getNotification().getAdditionalData();
                Log.i("OneSignalExample", "Notification Data: " + data);
                String notification_topic;
                if (data != null) {
                    notification_topic = data.optString("notification_topic", null);
                    if (notification_topic != null) {
                        OneSignal.addTrigger("notification_topic", notification_topic);
                    }
                }
            }
        });

I only have 3 method to use in OneSignal. Any idea why? Thanks
image

Code of Conduct

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

jennantilla commented Aug 25, 2023

@irinapopova124 thanks for reaching out! It looks like you might be using version 5.0.0 of our SDK--can you confirm? If that's the case then we have updated this method.

You will want to use addClickListener instead.

Let us know if that helps!

@irinapopova124
Copy link
Author

//Import OneSignal
implementation 'com.onesignal:OneSignal:[5.0.0, 5.99.99]'

But still, the problem is that I need the setNotificationOpenedHandler so that when the user clicked on the notification, I can extract the additional data.

The docs on addClickListener is not elaborate enough on how to do this. Could you let us know, thanks a lot @jennantilla

@rosebm
Copy link

rosebm commented Nov 10, 2023

You can still fetch the data @irinapopova124 with the clickListener, checking it I can see you can get it through its override method onClick. In kotlin:

OneSignal.Notifications.addClickListener(object: INotificationClickListener {
            //instead of setNotificationOpenedHandler 
            override fun onClick(event: INotificationClickEvent) {
                val data = event.notification.additionalData
                val launchUrl = event.notification.launchURL
                val androidNotificationId = event.notification.androidNotificationId.toString()
                println("clicked $data, $launchUrl, $androidNotificationId")
            }
        })

Here the doc: https://documentation.onesignal.com/docs/sdk-notification-event-handlers

@msencenb
Copy link

What about the the Foreground Listener found here? Is there sample code or references in Kotlin for handling that case?

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

4 participants