Mobile notifications wrapper gives error on Android

Hi, I’m using Unity’s mobile notifications wrapper script as shown in here: GitHub - Unity-Technologies/NotificationsSamples: Sample project for Unity Notifications My code is this:

GameNotificationsManager manager = Camera.main.GetComponent<GameNotificationsManager>();
        var channel = new GameNotificationChannel("default", "Default Game Channel", "Generic notifications");
        if (!manager.Initialized)
        {
            manager.Initialize(channel);
        }
        IGameNotification notification = manager.CreateNotification();
        notification.Title = "Come back!";
        notification.Body = "Your energy is full. Come back and run!";
        //DateTime deliveryTime = DateTime.Now.AddHours(4);
        DateTime deliveryTime = DateTime.Now.AddSeconds(4);
        notification.DeliveryTime = deliveryTime;
        manager.ScheduleNotification(notification);

When I debug the app on my phone I get this error:

AndroidJavaException: java.lang.NoSuchMethodError: no non-static method with name='registerNotificationChannel' signature='(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;ZZZZ[II)V' in class Ljava.lang.Object;
    java.lang.NoSuchMethodError: no non-static method with name='registerNotificationChannel' signature='(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;ZZZZ[II)V' in class Ljava.lang.Object;
        at com.unity3d.player.ReflectionHelper.getMethodID(Unknown Source:180)
        at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
        at com.unity3d.player.UnityPlayer.c(Unknown Source:0)
        at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:214)
        at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
      at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0
      at UnityEngine.AndroidJNISafe.CallStaticObjectMethod (System.IntPtr clazz, System.I

And the notifications doesn’t work. I’ve searched for the error code but couldn’t find an answer helping me. Could someone help me about this issue?

I have created an empty project and used same code and the outcome is the same as well. I’m using IL2CPP.
Edit: Issue resolved when I updated to the preview mobile notifications package.

4 Likes

You saved my day!!

2 Likes