Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Official Mobile Notification Package

Discussion in 'Android' started by _Paulius, Jan 28, 2019.

  1. rpassareti_

    rpassareti_

    Joined:
    Jan 18, 2018
    Posts:
    6
    I'm trying to clear the notifications and the badge number when you open the app, but something is missing for me

    I read in one post, to call "AndroidNotification.ShouldAutoCancel", but it only works if you click in the notification, if you click the icon, nothings changes
    and if it's 3 notification, only one is dismiss, the other 2 keeps there.

    any tips or idea?
     
    PlanarBit likes this.
  2. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,936
    Can you please share it with community?
     
  3. max427857

    max427857

    Joined:
    Sep 9, 2020
    Posts:
    8
    jGate99 likes this.
  4. max427857

    max427857

    Joined:
    Sep 9, 2020
    Posts:
    8
    jGate99 likes this.
  5. KateKhinkelIridescent

    KateKhinkelIridescent

    Joined:
    Aug 21, 2020
    Posts:
    9
    Even though this tred is about another classes it helped us with the same issue as yours! https://github.com/Unity-Technologies/NotificationsSamples/issues/30#issuecomment-694433072

    We use package 1.3.0 and Unity 2019.4.10

    add to proguard file this:
    -keep class com.unity.** { *;}
    -keep class com.unity.androidnotifications.* { *;}
    -keepclassmembers class com.unity.androidnotifications.* { *;}
    -keepnames class com.unity.androidnotifications.* { *;}
    -keepclassmembernames class com.unity.androidnotifications.* { *;}
     
  6. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,936
  7. max427857

    max427857

    Joined:
    Sep 9, 2020
    Posts:
    8
    No. it's kind of a pure check for notifications enabled. I don't know about calling the confirmation window (by the idea it is possible to realize, if necessary, but it is also possible to do with the game window).
     
    jGate99 likes this.
  8. thiagolrosa

    thiagolrosa

    Joined:
    Feb 22, 2017
    Posts:
    60
    @_Paulius, grouping notifications on Android doesn't seem to be working.

    I set the same group identifier and the summary to true, but both notifications are displayed separately. I'm using the SendNotificationWithExplicitID with two different ids.

    Any idea? Do you need more info?
     
  9. thiagolrosa

    thiagolrosa

    Joined:
    Feb 22, 2017
    Posts:
    60
    Is anyone here able to group android notifications using this plugin?
     
  10. m-Stratikopoulos

    m-Stratikopoulos

    Joined:
    Feb 19, 2014
    Posts:
    9
    I'm sorry, i know this is reported here again but i m kind of lost on all these 10 pages.
    GetLastRespondedNotification on IOS always returns null, when you use Firebase cloud messaging as well.
    This is also reported on firebase team
    https://github.com/firebase/quickstart-unity/issues/631

    Is there any update on this, maybe workarounds?
     
    Last edited: Nov 11, 2020
  11. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    167
    I have the same issue with Android and iOS but I thought it was a bug in my code (the order in which scripts are executed). Since users rarely remove apps from background, I gave up on searching a problem and solution.
     
  12. maidamedia

    maidamedia

    Joined:
    Nov 19, 2009
    Posts:
    224
    Hi, how is it possible to have a notification like this?
     
  13. maidamedia

    maidamedia

    Joined:
    Nov 19, 2009
    Posts:
    224
    I am interested too, did you find an answer to this question? Thx
     
  14. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    163
    Not possible with this asset.
    I'd like it too.
     
  15. maidamedia

    maidamedia

    Joined:
    Nov 19, 2009
    Posts:
    224
    did you find an alternative?
     
  16. Kholeslaw

    Kholeslaw

    Joined:
    May 7, 2013
    Posts:
    35
    hi @Vincent-Zhang @_Paulius. Is this package still maintained?

    I can set notifications. When the player taps a notification, it will open the game and I can capture the IntentData and send the player to the expected screen.

    This works if the game is shut down.
    I call GetLastNotificationIntent once the game has loaded up and I can get the IntentData.

    It also appears to work when the game is dormant in the background.
    I call GetLastNotificationIntent inside OnApplicationFocus and check if there is IntentData.

    The above also appears to work if you tap a notification sitting in the notification bar.

    What I want to know is how to capture the notification IntentData when the player taps a notification while the game is open and in the foreground. I want to use the notification to alert the player of an important event while they are playing and use it to jump the player to the right part of the game if they tap on the notification.

    Tapping a notification while the game is running appears to communicate with the app. What is the best way to capture this event so I can request the IntentData?

    Thanks!
     
  17. unity_OSeBXw9aivkTJg

    unity_OSeBXw9aivkTJg

    Joined:
    Jul 8, 2019
    Posts:
    19
    Hey guys, sorry if this was already asked, but couldn't find anything similar. I have an issue with Unity 2020.1.9f1 and Mobile Notifications 1.0.3 package. In Player settings, I have added 2 custom notification icons, but after that, I cannot edit them any more - the menu is empty, and when I click the plus icon, it just gets disabled.
    Screenshot 2020-12-16 at 10.33.28.png
    I have also tried manually editing the asset file, but it didn't work, here is how it looks like at the moment:
    Screenshot 2020-12-16 at 10.34.52.png
    So now, the custom small icon that I have set doesn't work - it just displays a white rectangle, but I cannot edit the settings, so I can't do anything about it? Notification icon size is 64x64 and it's fully white.
     
  18. Vaidas_B

    Vaidas_B

    Unity Technologies

    Joined:
    Jun 17, 2016
    Posts:
    18
    Hi! This issue should no longer occur in the latest verified version of the package (1.3.2).
     
  19. Cypras

    Cypras

    Joined:
    Oct 25, 2013
    Posts:
    64
    When using Get Last Notification, it doesn't clear the old notification unless the app is closed via Application.Quit.

    This really isn't feasible with users who always put the app to the background.

    What's the solution for that?
     
  20. DamonJager

    DamonJager

    Joined:
    Jul 16, 2015
    Posts:
    56
    how should I download the latest version? it isn't available in the package manager (the latest is the 1.0.3 preview).
     
  21. marcolbx

    marcolbx

    Joined:
    Mar 4, 2019
    Posts:
    11
    This is happening on version 1.3.2 & Unity 2019.4.8f1 on a Samsung S9+ (possibly on more Samsungs):
    1- Have a Samsung S9+ set to energy saving mode.
    2- Schedule two notifications.
    3- Quit the application entirely (remove it from the taskbar).
    4- You should only get one notification and the other (possibly) when re-starting the app (the second one may not appear).

    Does anybody has the same behaviour?
    Help would be appreciated.
     
    Last edited: Dec 22, 2020
  22. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,875
    1.3.2 version is compatible with 2019.4 and above, maybe you're using an older Unity version.
     
  23. Luchunpen_0

    Luchunpen_0

    Joined:
    Aug 7, 2014
    Posts:
    58
    Hello.
    I have a question:
    I create notifications on Android using NotificationSamplers. Notifications are created succsessfully, but after device restarting they dissapear, application icon not marked that it has notifications.

    Using Unity 2020.1.13, MobileNotifications 1.3.2, "Reschedule on device restart" toggle is on.

    On IOS devices if the application was started, all notifications disappear.
    Can I manually delete notifications that have been viewed and leave the rest ?
     
    Last edited: Dec 29, 2020
  24. timbokoppers

    timbokoppers

    Joined:
    Nov 14, 2016
    Posts:
    71
    I can't find any info if the latest version of this package support remote / push notifications on Android? So far I can see it only support local notifications, is that still correct? If so, are there plans to support this in the near future?

    Right now the only solution to get remote / push notifications working is to use Firebase Cloud Messaging, correct?
     
  25. Luchunpen_0

    Luchunpen_0

    Joined:
    Aug 7, 2014
    Posts:
    58
    One more question: How to get/set notifications count on the application icon on Android ?
     
  26. mentalup

    mentalup

    Joined:
    Dec 14, 2017
    Posts:
    7
    Is there any update on iOS iOSNotificationCenter.GetLastRespondedNotification() always return null bug? I can set the notification and schedule it everyrhing works perfect but I can not read it and we need the data inside notification.
     
  27. seigman667

    seigman667

    Joined:
    Aug 30, 2013
    Posts:
    4
    Unity 2019.4.18f1
    Mobile Notifications 1.3.2

    I am scheduling 20 notifications with each their own location trigger on iOS. The problem I'm seeing is that when one of these notifications is triggered in the app, all the notifications are triggered.

    I've looked through the source of the notifications package, and found the problem to be that you're using the same identifier for all regions used with the location trigger;

    UnityNotificationManager.m:288
    Code (csharp):
    1. CLCircularRegion* region = [[CLCircularRegion alloc] initWithCenter: center radius: data->locationTriggerRadius identifier: @"Headquarters"];
    I added locationTriggerIdentifier to iOSNotificationData (and iOSNotificationLocationTrigger.Identifier) and used it for the identifier when creating the CLCircularRegion object. Now only the correct notification is triggered in the app.

    Could you please update the package for next version with this fix?
     
    Last edited: Feb 10, 2021
  28. Luchunpen_0

    Luchunpen_0

    Joined:
    Aug 7, 2014
    Posts:
    58
    Same problem on IOS, but I'm getting notifications count in application and re-set it after each notification activation.
     
  29. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
  30. Luchunpen_0

    Luchunpen_0

    Joined:
    Aug 7, 2014
    Posts:
    58
    I' m not sure, I think it is represetation of one notification.
    I meant to set total notifications count, like iOSNotificationCenter.ApplicationBadge
     
    Last edited: Feb 17, 2021
  31. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    118
    Sorry if I missed but how can I replace old(delivered) notification with new one? It would be great if we have such in channel settings.
    And one more question. I need to show notifications only when app is in background. I schedule notifications when OnApplicationFocus(false) and disable them when OnApplicationFocus(true) with AndroidNotificationCenter.CancelAllNotifications(); Also I do it in OnApplicationQuit event.
    But If user goes OnApplicationFocus(false) and then destroys app activity outside the app, OnApplicationQuit event isn't fired all scheduled notifications contiue to deliver. Any suggestions?
     
    Last edited: Feb 23, 2021
  32. anibal-redwolf

    anibal-redwolf

    Joined:
    Nov 10, 2020
    Posts:
    1
    Hi there guys! I wanted to try this package, but my project is currently using Unity 2019.2.17f1 for the moment, and I would prefer to not upgrade it yet. I've just read here that the latest 1.3.0 package is for Unity 2019.4 and above... is there an older package compatible with my version of Unity? Thanks!

    EDIT: Never mind, just tried the last package version (1.3.0) and works well :)
     
    Last edited: Feb 23, 2021
  33. NMJ_GD

    NMJ_GD

    Joined:
    Dec 28, 2019
    Posts:
    14
    Hello, everyone! I can't seem to find how to change default notification sound for iOS. Can you help please?
     
  34. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    NMJ_GD likes this.
  35. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    118
    What about my questions?
     
  36. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    You can remove and schedule new notification. Have a look at these APIs:
    https://docs.unity3d.com/Packages/c...ations.Android.AndroidNotificationCenter.html

    OnApplicationFocus(false) is probably the place where you should be scheduling notifications, quit is not guaranteed to be invoked. You also probably want to cancel only scheduled notification, rather than all of them.
     
  37. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    118
    Do you mean this - public static void CancelDisplayedNotification(int id) ?
    I'm sure it works but only if your app is in foreground. But in background we can't exucute any code on mobile devices. My app is a some kind of timer with period. I'm scheduling notifications when app goes in background (no need notifications in foreground). And when users recieve notification they don't need to open app, just wait for next one. And I would like to show only last one (actual) notification in status bar.

    And when user finished using app he can kill it swiping up, out of ram, without app focusing. In this case user don't need to recieve any more notifications. So it should be like KILL APP => KILL ITS NOTIFICATIONS.

    Is it possible with this plugin?
     
  38. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    I don't think this is possible. Try reading official android documentation on notifications. If the feature you needs is not provided by android, then the only option is to write an android service that will run in background and manually deal with notifications.
     
  39. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    Some of our users sometimes get an EndOfStreamException when our app creates notifications:
    Code (CSharp):
    1. Non-fatal Exception: java.lang.Exception
    2. EndOfStreamException : Unable to read beyond the end of the stream.
    3. at System.IO.__Error.EndOfFile(System.IO.__Error)
    4.        at System.IO.BinaryReader.ReadByte(System.IO.BinaryReader)
    5.        at NotificationSamples.DefaultSerializer.Deserialize(NotificationSamples.DefaultSerializer)
    6.        at NotificationSamples.GameNotificationsManager.OnForegrounding(NotificationSamples.GameNotificationsManager)
    7.        at NotificationSamples.GameNotificationsManager.Initialize(NotificationSamples.GameNotificationsManager)
    8.        at PushNotifications.Create()
    Until now, this happend on these devices:
    • Redmi 6A (Android 9)
    • Moto C Plus (Android 7)
     
  40. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    This looks like a bug in your own code. I can't find any of the classes from callstack in notifications package.
     
  41. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    @Aurimas-Cernius The GameNotificationsManager class is inside your sample project!
     
  42. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
  43. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    @Aurimas-Cernius I imported the samples directly through the Package Manager, so I don't know if this repo is what you guys are using for this, but it looks about right.
    When are these fixes added to the Package Manager?
     
  44. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    @Aurimas-Cernius Applying the fix from the pull request results in another exception:
    Code (CSharp):
    1. Non-fatal Exception: java.lang.Exception: ArgumentOutOfRangeException : Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.
    2. Parameter name: ticks
    3.        at System.DateTime..ctor(System.DateTime.)
    4.        at NotificationSamples.DefaultSerializer.Deserialize(NotificationSamples.DefaultSerializer)
    5.        at NotificationSamples.GameNotificationsManager.OnForegrounding(NotificationSamples.GameNotificationsManager)
    6.        at NotificationSamples.GameNotificationsManager.Initialize(NotificationSamples.GameNotificationsManager)
    7.        at PushNotification.Create(PushNotification)
    8.        at SplashScene+<init>d__30.MoveNext(SplashScene+<init>d__30)
    9.        at System.Threading.ContextCallback.Invoke(System.Threading.ContextCallback)
    10.        at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext)
    11.        at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run(System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner)
    12.        at System.Action.Invoke(System.Action)
    13.        at System.Action`1[T].Invoke(System.Action`1[T])
    14.        at Cysharp.Threading.Tasks.UniTaskCompletionSourceCore`1[TResult].TrySetResult(Cysharp.Threading.Tasks.UniTaskCompletionSourceCore`1[TResult])
    15.        at RemoteConfig+<Create>d__11.MoveNext(RemoteConfig+<Create>d__11)
    16.        at System.Action.Invoke(System.Action)
    17.        at System.Action`1[T].Invoke(System.Action`1[T])
    18.        at Cysharp.Threading.Tasks.UniTaskCompletionSourceCore`1[TResult].TrySetResult(Cysharp.Threading.Tasks.UniTaskCompletionSourceCore`1[TResult])
    19.        at RemoteConfig+<initialize>d__12.MoveNext(RemoteConfig+<initialize>d__12)
    20.        at System.Action.Invoke(System.Action)
    21.        at System.Threading.ContextCallback.Invoke(System.Threading.ContextCallback)
    22.        at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.Tasks.AwaitTaskContinuation)
    23.        at System.Threading.Tasks.Task.FinishContinuations(System.Threading.Tasks.Task)
    24.        at System.Threading.Tasks.Task`1[TResult].TrySetResult(System.Threading.Tasks.Task`1[TResult])
    25.        at System.Threading.Tasks.TaskCompletionSource`1[TResult].TrySetResult(System.Threading.Tasks.TaskCompletionSource`1[TResult])
    26.        at System.Threading.Tasks.TaskCompletionSource`1[TResult].SetResult(System.Threading.Tasks.TaskCompletionSource`1[TResult])
    27.        at Firebase.FutureBool+<GetTask>c__AnonStorey0.<>m__0(Firebase.FutureBool+<GetTask>c__AnonStorey0)
    28.        at Firebase.FutureBool+Action.Invoke(Firebase.FutureBool+Action)
    29.        at Firebase.FutureBool.SWIG_CompletionDispatcher(Firebase.FutureBool)
    30.        at Firebase.AppUtilPINVOKE.PollCallbacks(Firebase.AppUtilPINVOKE)
    31.        at Firebase.AppUtil.PollCallbacks(Firebase.AppUtil)
    32.        at Firebase.Platform.FirebaseHandler.Update(Firebase.Platform.FirebaseHandler)
    This maybe comes from how old notifications were saved?
     
  45. JorisEertink

    JorisEertink

    Joined:
    Mar 15, 2017
    Posts:
    24
    Hi @Tomas1856 @Aurimas-Cernius @Vaidas_B ,

    Could you guys add the ProvisionalAuthorization option to the iOS Authorization Options? We want to implement "Quiet Notifications" and for this it requires to add UNAuthorizationOptionProvisional to the request. Currently on the Unity side it only supports Badge, Sound, Alert and CarPlay.

    Regards,

    Joris
     
  46. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    I'll look into it.
     
    JorisEertink likes this.
  47. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    493
    @Aurimas-Cernius
    Can you tell me what's the deal with iOSNotificationCalendarTrigger? I'm trying to queue daily notifications at the exact hour of the day. Sounds simple, right?

    Code (CSharp):
    1. var timeTrigger = new iOSNotificationCalendarTrigger()
    2. {
    3.    Hour = 12,
    4.    Minute = 0,
    5.    Second = 0,
    6.    Repeats = true
    7. }
    Now, if I wanted to cancel this notification for today only it would be completely impossible? The best I can do is set the "Day" to tomorrow's date, but then this notification repeats only once a month, therefore, instead of using one repeating notification, I have to create X non-repeating notifications just so I can cancel one from time to time.

    AndroidNotifications support this feature fine. I just set their fireTime to tomorrow and set that they repeat daily. I don't understand why iOS has such a different and limited implementation.
     
  48. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
  49. Smokedsalmo

    Smokedsalmo

    Joined:
    Jun 11, 2018
    Posts:
    2
    Hi All, I have a problem, within the namespace Unity.Notification.Android the Notification part does not exist. The problem has arisen after importing the project into a different version. I have tried reimporting the project advertised at the top of this thread.

    Thankyou for your time.
     
  50. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    It is Notifications in there. Maybe it was named using singular in the past, but current version is plural.