as title says, I can’t get my android app to send notifications.
I followed unity’s tutorial, and tried many variations. Here’s my current code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Android;
using UnityEngine;
using Unity.Notifications.Android;
using UnityEngine.UI;
public class MainManager : MonoBehaviour
{
public Text dateText;
AndroidNotificationChannel channel;
void Start()
{
dateText.text = System.DateTime.UtcNow.ToLocalTime().ToString("dd / MM yyyy");
SetupChannel();
DoNotif();
}
private void SetupChannel()
{
channel = new AndroidNotificationChannel()
{
Id = "default_channel",
Name = "Default channel",
Description = "",
Importance = Importance.Default,
};
AndroidNotificationCenter.RegisterNotificationChannel(channel);
}
public void DoNotif()
{
var notification = new AndroidNotification();
notification.Title = "SomeTitle";
notification.Text = "SomeText";
notification.FireTime = System.DateTime.Now.AddSeconds(5);
var id = AndroidNotificationCenter.SendNotification(notification, "default_channel");
}
}
It does not work. No notification is sent. I do not understand why, since I’ve followed the steps given in the tutorial.
And what have you found so far by googling the above error?
This is just basic debugging / troubleshooting 101… even someone who has used these APIs every single day has to do this because they do change over time and suddenly stop working. It’s important to be ready to google stuff.
using UnityEngine;
using Unity.Notifications.Android;
using System;
public class Notificationmanager : MonoBehaviour
{
public void Start()
{
var c = new AndroidNotificationChannel()
{
Id = "notif1",
Name = "openreminder",
Importance = Importance.High,
Description = "Remind the play to open the app",
};
AndroidNotificationCenter.RegisterNotificationChannel(c);
SendNotification();
//SendAnotherNotification();
}
void SendNotification()
{
var notification = new AndroidNotification();
notification.Title = "Bla Bla Bla";
notification.Text = "Bla Bla Bla";
notification.FireTime = DateTime.Now.AddSeconds(10);
notification.LargeIcon = "icon_1";
notification.SmallIcon = "icon_0";
AndroidNotificationCenter.SendNotification(notification, "notif1");
}
}
Hello.
I had the same issues. Notifications on the Android emulator were received with a delay of 75% of the time, e.g. set for 2 minutes and received in 3.5 minutes.
When testing on a real Android device, the notification didn’t appear until the app was launched again.
And I’ve found the solution:
go to “Project settings”
select “Mobile notifications”
in “Android” tab at “Schedule at exact time” select “Everything”
Yes this works, however you run into issues when you try to publish this app in play store. Exact notification permissions are only allowed for calendar and clock applications.