0
\$\begingroup\$

When my app starts I check whether there is a notification or not

  • if there isn't I create one via SendNotification(...)

  • if there is, I check their status:

    • var status = CheckScheduledNotificationStatus(notificationId);

    • On my Xiaomi their status is Scheduled, so I update them:

      • SendNotificationWithExplicitID(...)
    • But on a Huwaei it's always Unknown, in that case I create a new:

      • SendNotification(...)

      • And replace the old ID in the PlayerPrefs.

      • But on the next startup it's unknown again.

Maybe I should use SendNotificationWithExplicitID(...) as well when the status is Unknown so I can keep the ID?

Here is the code:

var notification = CreateNotification(jsonWrapper.Name, fireTime, title, text);
if (PlayerPrefs.HasKey(jsonWrapper.Name))
{
    var notificationId = PlayerPrefs.GetInt(jsonWrapper.Name);
    var status = AndroidNotificationCenter.CheckScheduledNotificationStatus(notificationId);
    if (status == NotificationStatus.Scheduled)
    {
        AndroidNotificationCenter.SendNotificationWithExplicitID(notification, "default", notificationId);
        Logger.Log($"Updated a notification: {jsonWrapper.Name} at {fireTime}.");
    }
    else if (status == NotificationStatus.Unknown)
    {
        var id = AndroidNotificationCenter.SendNotification(notification, "default");
        PlayerPrefs.SetInt(jsonWrapper.Name, id);
        PlayerPrefs.Save();
        Logger.Log($"UnknownStatus | Registered a new notification: {jsonWrapper.Name} at {fireTime}.");
    }
}
else
{
    var id = AndroidNotificationCenter.SendNotification(notification, "default");
    PlayerPrefs.SetInt(jsonWrapper.Name, id);
    PlayerPrefs.Save();
    Logger.Log($"Registered a new notification: {jsonWrapper.Name} at {fireTime}.");
}
\$\endgroup\$
0
\$\begingroup\$

I had to go into the Settings, and enable more permissions. (Don't know which one sadly)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.