Mobile Notifications - Not working?

Hello everybody

Hope I am in the good thread.

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…

Do you have also a problem?

Have a great day :slight_smile:

Hello everybody,

“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?

Did you find a way on how to make it work?

Oops. Forgot to post the solution :

Under Project Settings then Player and finally Publishing Settings, uncheck the box Release and Debug under the section Minify.

And Voilà! :slight_smile:

2 Likes

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

5 Likes

Do you mean setting them both to None? They are both None and still, I do not receive any notifications in my build (android)

1 Like

Yep. I have just unchecked them both. Since I have implanted this feature in July, here is my experience:

  • It doesn’t work on my phone. I need to open the app to see the notification… No sense
  • It work perfectly on others friends phone.

If I found something, I will tell but you.

Did you tried the ways that @Pranav_Redstoneinvente said?

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 ?

Are those work even If you publish your app ? Have you tried those in published app ?

Hello @halimozturk

If i remember, it worked properly when I have published the App but not in test environment. Completly the opposite :frowning:
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

EDIT2: Did you build your project in APK or AAB? Read the “Knows issues” : Unity | Mobile notifications – PROTOKOLL Studio

PS: Maybe I need to remove the status “Resolved”

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.

Thank you for your quick reply too.

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…

Yes! Let me know :smile:

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 :slight_smile: In the mean time you can test this in your own project.

nopes i did not yet published my app

Hope it will work for you! I will try that today :slight_smile:

1 Like

Good News :slight_smile: 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.

1 Like

Oh good to read! What’s your app?

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 :frowning:

var notification = new AndroidNotification(title, text, System.DateTime.Now, new System.TimeSpan(72,0,0));

This is my app https://play.google.com/store/apps/details?id=com.EeGames.PopBlast
You don’t need to uncheck Release it’s checked on my project and build it as aab. That’s it.

Thank you for your answers and the link :slight_smile:
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…

This works for me

    public void SchudleNotification(string title, string text, string iconSmall, string iconLarge, int notificationTime, string notificationType)
    {
        AndroidNotificationCenter.SendNotification(new AndroidNotification()
        {
            Title = title,
            Text = text,
            SmallIcon = iconSmall,
            LargeIcon = iconLarge,
            FireTime = System.DateTime.Now.AddSeconds(notificationTime)
        },
        CreateChannels(notificationType));
    }

    private string CreateChannels(string notificationType)
    {
        string channelID = "ChID_" + notificationType;
        var channelDefault = new AndroidNotificationChannel()
        {
            Id = channelID,
            Name = notificationType.ToString(),
            Description = "Default Description",
            Importance = Importance.Default,
        };
        AndroidNotificationCenter.RegisterNotificationChannel(channelDefault);
        return channelID;
    }
2 Likes