OneSignal / OneSignal-Xamarin-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Xamarin app with OneSignal. https://onesignal.com
Other
104 stars 50 forks source link

[question]: How to create Android Notification Service Extension in xamarin #348

Closed phamhuudat closed 1 year ago

phamhuudat commented 1 year ago

How can we help?

my project install version onesignal 4.3.0 I want custom Android Notification Service. Please guide me how to edit. thankyou. Now, I code follow with this link: https://documentation.onesignal.com/docs/service-extensions#android-notification-service-extension But not work with me. code demo using static Com.OneSignal.Android.OneSignal; using Com.OneSignal.Android public class NotiServiceExtension : Java.Lang.Object, IOSRemoteNotificationReceivedHandler {

    public void RemoteNotificationReceived(Context context, OSNotificationReceivedEvent p0)
    {
    }

}

Code of Conduct

Acilec commented 1 year ago

Same problem here... Can't find any working documentation for 4.x.x regarding this.

phamhuudat commented 1 year ago

I resolved it Class Extension in android, i register name class c# after jni to java [Register("com/company/dev/NotificationServiceExtension")] Example: using static Com.OneSignal.Android.OneSignal; using Com.OneSignal.Android [Register("com/company/dev/NotificationServiceExtension")] public class NotificationServiceExtension: Java.Lang.Object, IOSRemoteNotificationReceivedHandler {

public void RemoteNotificationReceived(Context context, OSNotificationReceivedEvent p0)
{
}

} in manifest android, i create code "meta-data android:name="com.onesignal.NotificationServiceExtension" android:value="com.company.dev.NotificationServiceExtension"/>"

It work OK

Dfergy commented 1 year ago

BTW, thank you @phamhuudat for posting this, I was trying to implement this as well and you filled in some blanks for me.