I am currently trying to implement the mobile notifications (v.1.3.2) with an android phone (Android v.11)
I tried to show the notification with a simple button but it doesn’t work. I can see my Debug.Log but not the notifications
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Notifications.Android;
public class NotificationManager : MonoBehaviour
{
// Start is called before the first frame update
public void SendNote()
{
var channel =
new AndroidNotificationChannel()
{
Id = "default_channel",
Name = "SpeedySquare",
Importance = Importance.Default,
Description = "channel_description"
};
AndroidNotificationCenter.RegisterNotificationChannel (channel);
var notification = new AndroidNotification();
notification.Title = "Speedy Square";
notification.Text = "Someone beat the highscore!";
notification.FireTime = System.DateTime.Now.AddSeconds(10);
AndroidNotificationCenter.SendNotification(notification, "default_channel");
Debug.Log("Send note");
}
}
I remember it worked with an old version of Android (v.9 in think) but now…
“Good news” : the notifications will only work when the project is builded with the status “Development Build”. But how to be sure it will work with the final version?
I actually found another way, simply adding
-keep class com.unity.** { ;}
-keep class com.unity.androidnotifications.* { ;}
-keepclassmembers class com.unity.androidnotifications.* { ;}
-keepnames class com.unity.androidnotifications.* { ;}
-keepclassmembernames class com.unity.androidnotifications.* { *;}
to the proguard works fine. LOL thanks tho
How about when we publish our apps ? Thanks for you I managed to get notifications work on test environment. However they are not pop up on published app. Do you have any solution for published apps ?
If i remember, it worked properly when I have published the App but not in test environment. Completly the opposite
And nope, I do not have tested the “keep class…” . May be interesting to implement.
Tell me if you have a solution.
EDIT: Tested my application again: the notifications doesn’t work well or no more for some of my friends… I will check that as soon as possible
Hi @Protokoll ,
Thank you for your very quick and kind response. I also don’t have tested “keep class…” but I’ll do it ASAP.
By the way If build apk and deselect release from publishing settings and create test apk it works fine. But I when I select release (I think I have to do that if I am going to publish) and create aab file for google play it doesn’t work.
I am trying to solve this and let you know if I got any solution. Removing status “Resolved” is completely up to you but it seems It is only resolved for test environment right now.
When I have builded the project as an aab file, the notification didn’t work anymore, only when I’ve checked “Development Build”. In this case, my current solution was to uncheck the box Release and Debug under the section Minify. But it seems that it doesn’t work anymore…
I’ve tried the @Pranav_Redstoneinvente 's proguard solution it works even if I build aab. Now I am uploading new bundle to Google Play. After approval I am gonna have to wait 24 hours to see actual results and let you know In the mean time you can test this in your own project.
Good News My app has been updated on Google Play and I fast forward the process by changing my phones local time, and the notification is working fine now, even the app is downloaded from play store. The problem is SOLVED by @Pranav_Redstoneinvente 's solution.
I am currently trying the answer of @Pranav_Redstoneinvente . I’ve unchecked Release/Debug under Minify (Player Settings) and checked “Custom Proguard File” and then adding the answer of pranav. Do I miss something else? I build the project with “App Bundle” (aab)
INFO: I am trying to implement that with my schedule notification.It works weirdly when the app is closed: sometimes it doesn’t appears
var notification = new AndroidNotification(title, text, System.DateTime.Now, new System.TimeSpan(72,0,0));
Thank you for your answers and the link
Do you have also a schedule notifications? Like: every x days, do you show a notification? It doesn’t seems to work well with my current code. I randomly can see the notification…