- Home /
Help with the new Mobile Notification System in Unity
Hello guys, I am trying to implement the notification system on the application I am building. To be more specific I want the notification to fire in a specific date and time I specify by creating a DateTime object first. Then, I want to schedule a new notification by updating the previous one but an error is showing 10-06 17:50:54.079: E/Unity(9839): AndroidJavaException: java.lang.NoSuchMethodError: no static method with name='checkIfPendingNotificationIsRegistered' signature='(I)Z' in class Ljava.lang.Object; 10-06 17:50:54.079: E/Unity(9839): java.lang.NoSuchMethodError: no static method with name='checkIfPendingNotificationIsRegistered' signature='(I)Z' in class Ljava.lang.Object; 10-06 17:50:54.079: E/Unity(9839): at com.unity3d.player.ReflectionHelper.getMethodID(Unknown Source) 10-06 17:50:54.079: E/Unity(9839): at com.unity3d.player.UnityPlayer.nativeRender(Native Method) 10-06 17:50:54.079: E/Unity(9839): at com.unity3d.player.UnityPlayer.c(Unknown Source) 10-06 17:50:54.079: E/Unity(9839): at com.unity3d.player.UnityPlayer$e$2.queueIdle(Unknown Source) 10-06 17:50:54.079: E/Unity(9839): at android.os.MessageQueue.next(MessageQueue.java:398) 10-06 17:50:54.079: E/Unity(9839): at android.os.Looper.loop(Looper.java:142) 10-06 17:50:54.079: E/Unity(9839): at com.unity3d.player.UnityPlayer$e.run(Unknown Source) 10-06 17:50:54.079: E/Unity(9839): at UnityEngine._AndroidJNIHelper.GetMethodID (System.IntPtr jclass, System.String methodName, System.String signature, System.Boolean isStatic) [0x00041] in :0 10-06 17:50:54.079: E/Unity(9839): at UnityEngine.AndroidJNIHelper.GetMethodID (System.IntPtr javaClass, System.String methodName, System.String si.
Here is my code:
void Start() {
var today = DateTime.Now;
DateTime today_evening = new DateTime(today.Year, today.Month, today.Day, 14, 0, 0,
DateTimeKind.Utc);
setEvening_Channel("3");
setEvening_Notification(today_evening, "3");
}
public void setEvening_Channel(string id_e)
{
var evening = new AndroidNotificationChannel()
{
Id = id_e,
Name = "Morning channel",
Importance = Importance.High,
Description = "Generic notification",
};
AndroidNotificationCenter.RegisterNotificationChannel(evening);
}
public void setEvening_Notification(DateTime tomo_even, string id_e)
{
//schedule the notification
var notification_evening = new AndroidNotification();
notification_evening.Title = "Just a Reminder";
notification_evening.Text = "Don't forget to add today's meal";
notification_evening.FireTime = tomo_even;
evening_identifier = AndroidNotificationCenter.SendNotification(notification_evening, id_e);
}
private void OnApplicationPause(bool pause)
{
if (AndroidNotificationCenter.CheckScheduledNotificationStatus(evening_identifier) ==
NotificationStatus.Delivered)
{
Debug.Log("DELIVERED STATUS ON EVENING NOTIFICATION");
var today = DateTime.Now;
//tommorows datetime strings
var tommorow_evening = new DateTime(today.Year, today.Month, today.Day, 18, 0, 0,
DateTimeKind.Local);
PlayerPrefs.SetString("tomorrow_evening", tommorow_evening.ToString());
// setMorning_Channel("4");
var notification_evening = new AndroidNotification();
notification_evening.Title = "Just a Reminder buddy";
notification_evening.Text = "Don't forget to add today's meal";
notification_evening.FireTime = tommorow_evening;
AndroidNotificationCenter.UpdateScheduledNotification(evening_identifier, notification_evening,"3");
Debug.Log("EVENING NOTIFICATION WAS UPDATED");
}
}
The error is showing when I run the UpdateScheduledNotification method.
Answer by trungvt1690 · Oct 12, 2019 at 04:01 PM
Method UpdateScheduledNotification has a bug. I checked version 1.0.3 and 1.0.4p3. They still not fix this. So, you can use SendNotificationWithExplicitID instead UpdateScheduledNotification, they are the same on current version. And wait they fix on next version.