Search Unity

Official Mobile Notification Package

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

  1. dbutrimov-wx

    dbutrimov-wx

    Joined:
    Jan 10, 2019
    Posts:
    1
    I have the same problem on iOS. Android is working fine.

    Unity 2018.4.8f1 + Mobile Notifications 1.0.3
     
    Last edited: Sep 13, 2019
  2. swordvoice

    swordvoice

    Joined:
    Jan 30, 2019
    Posts:
    2
    Hello I can't seem to get the notification to repeat with AndroidNotification.RepeatInterval It did show on FireTime but doesn't show after the time I set with RepeatInterval past does anyone get it to work yet or is there any other way that can show notification every week like on every sunday?
     
  3. ZerotheLone

    ZerotheLone

    Joined:
    Nov 9, 2017
    Posts:
    16
    I keep getting namespace errors every time I try to build (please see below). But in my code there are no error, when I type in 'using Unity.Notifications.iOS' it appears just fine. Anybody know what may be wrong?

    Code (CSharp):
    1. Assets\Scripts\Main Scripts\NotificationSystem\NotificationSystem.cs(12,27): error CS0234: The type or namespace name 'iOS' does not exist in the namespace 'Unity.Notifications' (are you missing an assembly reference?)
    2.  
    3. Assets\Scripts\Main Scripts\NotificationSystem\NotificationSystem.cs(40,13): error CS0246: The type or namespace name 'iOSNotificationCenter' could not be found (are you missing a using directive or an assembly reference?)
    4.  
    5. Assets\Scripts\Main Scripts\NotificationSystem\NotificationSystem.cs(41,14): error CS0246: The type or namespace name 'AuthorizationStatus' could not be found (are you missing a using directive or an assembly reference?)
     
  4. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    @swordvoice an issue caused repeatable notifications to not work on Android was fixed in 1.0.4-preview.1

    @EDG_Chris, @dbutrimov-wx "GetLastRespondedNotification" seems to work fine for me on 1.0.4-preview.2. Could you submit a bug report with Unity's bug reporter and include the script you're using?

    Also "com.unity.mobile.notifications@1.0.4-preview.2" was just published:
    - Fixed some issues with the Notification Samples project and the latest preview version of the package.
    - Also the sample proejct is not embeded in the package and can be added to your project using the Pacakage Manager UI.
     
    Livealot likes this.
  5. joseibanez

    joseibanez

    Joined:
    Nov 18, 2017
    Posts:
    6
    Hello @_Paulius ! Is there a way to increment automatically the Badge number, for iOS notifications? I know that we can set that number using iOSNotificationCenter.ApplicationBadge, but how can we set it as the amount of delivered notifications when the app isn't running? Right now I always get a "1" when there are one or more notifications delivered. Thank you in advance.
     
    Last edited: Sep 18, 2019
  6. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    @joseibanez as far I know there is no way to do that without having the app run in the background. You can also set a specific number for each notification through "iOSNotification.badge" but than won't really help in this case.
     
  7. Ponytech

    Ponytech

    Joined:
    Jun 13, 2016
    Posts:
    33
    @_Paulius This statement dated back in February. Any news on supporting push notifications on Android?

    In the meantime, anyone can recommend a plugin which handles push notifications on Android?
     
    timbokoppers likes this.
  8. swordvoice

    swordvoice

    Joined:
    Jan 30, 2019
    Posts:
    2
    @_Paulius thank you, I update package ver in my project and it work great
     
  9. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    After importing the 1.0.3 package into a project on 2018.4.8 I get this warning:

    No script asset for UnityNotificationEditorManager. Check that the definition is in a file of the same name and that it compiles properly.

    The UnityNotificationEditorManager script is present in Packages/Mobile Notifications/Editor.
     
  10. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    I have a bug in Project Settings on 2018.4.8.

    If I uncheck 'Request Authorization on App Launch' option then click to different settings, e.g. Physics, then when I return to Mobile Notification Settings the option is checked again.
     
    leynier41 likes this.
  11. angelkyriako

    angelkyriako

    Joined:
    May 21, 2013
    Posts:
    7
    Hi @_Paulius, we have two particular issues with the package specifically for ANDROID 5 (Lollipop):

    - The icon color is not painted and thus the user cannot see anything (white icon on white background).
    Here is a relevant link

    - The timestamp does not appear when the notification is not expanded

    Is there any way to work around these issues ?
     
  12. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    How is it? It's not about where to find related settings in Editor. Increasing minSdkVersion drops ~100K of users for our game on Android versions from 4.1 API 16 to 4.3 API 18!

    When is it planned to be fixed back to API 16? How can I work around this issue until then?
     
    ArthurAulicino and mvaz_p like this.
  13. mvaz_p

    mvaz_p

    Joined:
    Aug 22, 2018
    Posts:
    80
    Any workarounds for minimum API Level below 19? We simply cannot afford to drop thousands of users because of this.
    The previous version (1.0.2) doesn't seem to work correctly with Custom Android Activity, used by Firebase Cloud Messaging.
     
    Qbit86 and ArthurAulicino like this.
  14. Divinitize1

    Divinitize1

    Joined:
    May 27, 2019
    Posts:
    101
    Can anyone help explain a bit better as to how a identifier is set, named, seleted on android?
    I have read the DOCS several times and still don't understand it.

    "Unity assigns a unique identifier to each notification after you schedule it."

    Sorry if this is a really obvious thing but i just cant understand what that means, can't i just cancel/reschedule notifications via the ID?

    This is my script

    Code (CSharp):
    1.   void Start()
    2.   {
    3.     RegisterDailyNotification();
    4.   }
    5.   public void RegisterDailyNotification()
    6.   {
    7.     if(save.notificationsActive && save.notifyDailyRewards)
    8.     {
    9.       var c = new AndroidNotificationChannel()
    10.       {
    11.         Id = "2",
    12.         Name = "DailyReward",
    13.         Importance = Importance.High,
    14.         Description = "Generic notifications",
    15.       };
    16.       AndroidNotificationCenter.RegisterNotificationChannel(c);
    17.  
    18.       var notification = new AndroidNotification();
    19.       notification.Title = "Daily Reward";
    20.       notification.Text = "Your Daily Reward Is Ready To Claim!";
    21.       notification.FireTime = System.DateTime.Now.AddHours(24);
    22.       notification.LargeIcon = "icon_1";
    23.       AndroidNotificationCenter.SendNotification(notification, "2");
    24.     }
    25.   }
    I just want to know how i can cancel that.
    And also just want to know if notifications come up while playing and if so can it be disabled.
    Thanks
     
  15. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    @andymads, @Angel-Kyriako thanks, we'll investigate these issues.

    @Qbit86 because this package is only verified for Unity 2019.3 in which the minimum supported Android version is raised to 4.4 we have decided to also change the minimum version supported by the package to 4.4. However The source of the package is now available in github. The Android library can be compiled manually by running the "build_package.sh" script and minimum version can be changed in "androidnotifications/build.gradle" (however I can not guarantee that future versions will continue to be compatible with Android versions before 4.4)


    @Divinitize1 yes, you can cancel the scheduled notification by using the returned identifier like this:
    Code (CSharp):
    1. var identifier = AndroidNotificationCenter.SendNotification(n, "channel_id");
    2. AndroidNotificationCenter.CancelNotification(identifier);
     
    Egil-Sandfeld and Qbit86 like this.
  16. Divinitize1

    Divinitize1

    Joined:
    May 27, 2019
    Posts:
    101
    I've ended up downloading the example project that was used in the Unity youtube video on notifications, the whole script is very different from what the Docs show,
    I still am absolutely puzzled by "identifier", and most importantly how it works with multple different notifications.
    In the example project script it's set as a private int, is the identifier just that of int? and I can use other ints for the other notifications?
     
    Last edited: Sep 29, 2019
  17. domdev

    domdev

    Joined:
    Feb 2, 2015
    Posts:
    375
    any fix for this? I got this too in unity 2019.3.8f1
     
  18. psynusoidal

    psynusoidal

    Joined:
    May 26, 2015
    Posts:
    14
    Each notification you schedule is given its own unique identifier (the return value of SendNotification(), always an int) so that you can refer to it later (e.g. if you want to cancel it, as demonstrated by @_Paulius above). If you schedule multiple notifications, each will be given its own id. Nothing more to it than that.
     
  19. Divinitize1

    Divinitize1

    Joined:
    May 27, 2019
    Posts:
    101
    So to be clear is this
    Code (CSharp):
    1. var identifier = AndroidNotificationCenter.SendNotification(n, "channel_id");
    Actually sending the notification, or is it just getting that sent notifications identifier?
    If it's the first, would I just name identifier1, identifier2 etc, and if it's the latter, that makes a lot more sense.
     
  20. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Please consider expanding audience of your package to those who use 2018.4 LTS.
     
  21. pablogamehouse

    pablogamehouse

    Joined:
    Aug 18, 2019
    Posts:
    2
    Hi @_Paulius, we're having problems registering devices for notifications when compiling the game with the iOS 13 SDK. The token returned from the AuthorizationRequest object is invalid. I looked into the native code to see what is happening, the problem is that the return value of the method description from the NSData class has been changed. Before the iOS SDK 13, this method returned a hexadecimal string representing its value, but now it returns a string containing more information, and truncated, e.g.:

    {length = 32, bytes = 0x8180372f bc8f5fde fc96a82a d3beb70f ... 75ac2da8 1d693d54 }

    In the file UnityAppController+Notifications.mm, when adding the observer for the notification
    kUnityDidRegisterForRemoteNotificationsWithDeviceToken, the code looks like this:

    manager.deviceToken = [NSString stringWithFormat:@"%@",notification.userInfo];

    The userInfo property of the notification object is a NSData (not a NSDictionary as the method signature expects), and when used like in the code above, it will invoke the description method to return a string representation of the object.

    To fix it, the device token must be converted to a string in a proper way:
    Code (Objective-C):
    1.  
    2. // convert the device token to a valid hex string...
    3. NSData *deviceToken = (NSData *) notification.userInfo;
    4. const unsigned char *buffer = (const unsigned char *) deviceToken.bytes;
    5. NSMutableString *stringToken  = [NSMutableString stringWithCapacity:(length * 2)];
    6. for (int i = 0; i < deviceToken.length; ++i) {
    7.      [stringToken appendFormat:@"%02x", buffer[i]];
    8.  }
    9. // use the correct device token string:
    10. manager.deviceToken = stringToken;
    11.  
    Is there an estimate of when an official fix will be released?
     
    Nieles_GH likes this.
  22. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    @pablogamehouse thanks for pointing this out, we'll have a fix later this week.

    @Divinitize1 yes, this sends (or schedules) the passed notification and returns an automatically generated identifier.
     
    pablogamehouse likes this.
  23. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    I've tried to rebuild the Android library, and for some unexpected reason I've succeeded, almost with the first attempt.
     
  24. Haukien

    Haukien

    Joined:
    Aug 20, 2014
    Posts:
    12
    Hi,

    We still see crashes on iOS with 1.0.3 using Unity 2018.4.6

    Fatal Exception: NSInvalidArgumentException
    0 CoreFoundation 0x1c704298c __exceptionPreprocess
    1 libobjc.A.dylib 0x1c621b9f8 objc_exception_throw
    2 CoreFoundation 0x1c6f4cbc0 -[NSCache init]
    3 Foundation 0x1c7996b04 +[NSString stringWithUTF8String:]
    4 gameName 0x104fc98f4 _ScheduleLocalNotification + 106 (UnityNotificationWrapper.m:106)
    5 gameName 0x106545fa8 (Missing)
    6 gameName 0x106545e70 (Missing)
    7 gameName 0x105ecd1b8 (Missing)
    8 gameName 0x105d2f55c (Missing)
    9 gameName 0x105d2df00 (Missing)
    10 gameName 0x104f60314 RuntimeInvoker_TrueVoid_t22962CB4C05B1D89B55A6E1139F0E87A90987017(void (*)(), MethodInfo const*, void*, void**) + 38974 (Il2CppInvokerTable.cpp:38974)
    11 gameName 0x105b78c70 il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**) + 539 (Runtime.cpp:539)
    12 gameName 0x1055b89e4 scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool) + 246 (ScriptingApi_Il2Cpp.cpp:246)
    13 gameName 0x1055c0868 ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool) + 347 (ScriptingInvocation.cpp:347)
    14 gameName 0x1055cacf0 MonoBehaviour::HandleNotifications(void*, int, MessageData&) + 71 (ScriptingInvocation.h:71)
    15 gameName 0x1053f07f8 GameObject::SendMessageAny(MessageIdentifier const&, MessageData&) + 1233 (GameObject.cpp:1233)
    16 gameName 0x10551de54 SendMessageToEveryone(MessageIdentifier const&, MessageData) + 1311 (GameObjectUtility.cpp:1311)
    17 gameName 0x10552e8e8 NotifyPlayerQuit(bool) + 298 (Player.cpp:298)
    18 gameName 0x10552f124 PlayerCleanup(bool) + 570 (Player.cpp:570)
    19 gameName 0x105795224 UnityCleanup + 227 (LibEntryPoint.mm:227)
    20 gameName 0x105795468 UnityPlayerLoopImpl(bool) + 297 (LibEntryPoint.mm:297)
    21 gameName 0x104e50f3c UnityRepaint + 280 (UnityAppController+Rendering.mm:280)
    22 gameName 0x104e50e18 -[UnityAppController(Rendering) repaintDisplayLink] + 72 (UnityAppController+Rendering.mm:72)
    23 QuartzCore 0x1cb452ff0 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long)
    24 IOKit 0x1c729f4b0 IODispatchCalloutFromCFMessage
    25 CoreFoundation 0x1c6fae19c __CFMachPortPerform
    26 CoreFoundation 0x1c6fd4da0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__
    27 CoreFoundation 0x1c6fd44ec __CFRunLoopDoSource1
    28 CoreFoundation 0x1c6fcf310 __CFRunLoopRun
    29 CoreFoundation 0x1c6fce7c0 CFRunLoopRunSpecific
    30 GraphicsServices 0x1c91cf79c GSEventRunModal
    31 UIKitCore 0x1f3953c38 UIApplicationMain
    32 gameName 0x104e487c0 main + 41 (main.mm:41)
    33 libdyld.dylib 0x1c6a928e0 start
     
    Last edited: Oct 7, 2019
  25. dozhwal

    dozhwal

    Joined:
    Aug 21, 2014
    Posts:
    59
    Hi,

    i'm on 2018.3.10f1. with 1.0.4 preview packages.
    On : a Redmi note 7 Android 9.0. (MUI is a little agressive on App killing)

    On a debug version, notifications don't survive closing app.
    On a real version, notifications survive closing app but don't survive reboot.

    Checkbox in Packages settings "reschedule at boot" is checked : Generated Manifest is okay with BOOT permissions at true.
    https://imgur.com/sfAofOX (android developer console permissions)
     
  26. TheTall2338

    TheTall2338

    Joined:
    Jul 5, 2015
    Posts:
    15
    Hi @_Paulius
    I have an issue with persisting notifications after a device reboot. I made sure the option is checked in the settings. I also checked the manifest and it seems the plugin is not adding the permission required. I am using version 1.0.4-preview.2.
     
  27. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    @pablogamehouse com.unity.mobile.notifications@1.0.4-preview.3 went out earlier today which has a fix for the deviceToken issue.
     
    pablogamehouse and Nieles_GH like this.
  28. pablogamehouse

    pablogamehouse

    Joined:
    Aug 18, 2019
    Posts:
    2
    Thanks @_Paulius!
     
  29. Vasilis62

    Vasilis62

    Joined:
    Nov 2, 2018
    Posts:
    15
    Good day @_Paulius

    I have imported the Mobile Notifications 1.0.3 package to my Unity project (I am using Unity 2018.4.0f), ticked the "Reschedule Notifications on Device Restart" box and also checked that the RECEIVE_BOOT_COMPLETED user permission in in my AndroidManifest after the build is made. Yet the notifications do not persist on the android. I tried resetting the Project Settings as well, to no avail. Any way to fix this?
     
    TheTall2338 and dozhwal like this.
  30. MagicMiikka

    MagicMiikka

    Joined:
    Aug 23, 2014
    Posts:
    14
    F/art (26313): art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xf0
    F/art (26313): art/runtime/check_jni.cc:65] string: 'We miss you '
    F/art (26313): art/runtime/check_jni.cc:65] in call to NewStringUTF
    F/art (26313): art/runtime/check_jni.cc:65] from boolean com.unity3d.player.UnityPlayer.nativeRender()
    F/art (26313): art/runtime/check_jni.cc:65] "UnityMain" prio=5 tid=34 Runnable

    Android 5.0.2
    SM-T530
    Unity 2018.4.1f1

    This type of string causes a crash on our users but it's not being caught and logged reported out as one and the application instead freezes after running to this error. Using 1.0.3 package.
     
  31. peisan

    peisan

    Joined:
    Sep 24, 2019
    Posts:
    1
    Hi @_Paulius,

    I disable Request Authorization on App Launch in mobile notification settings, however it is still showing when the app launches, is this a bug?

    Unity version: 2018.4.9
     
    leynier41 likes this.
  32. ksc_3899

    ksc_3899

    Joined:
    Jan 1, 2019
    Posts:
    30
    Code (CSharp):
    1. public class MobileNotificationManager : MonoBehaviour
    2. {
    3.  
    4.     public AndroidNotificationChannel defaultNotificationChannel;
    5.     public string[] runtimeNotificationTexts;
    6.     public string[] notificationTexts;
    7.  
    8.     private int identifier;
    9.  
    10.     private void Start()
    11.     {
    12.  
    13.         defaultNotificationChannel = new AndroidNotificationChannel()
    14.         {
    15.             Id = "default_channel",
    16.             Name = "Default Channel",
    17.             Description = "For Generic notifications",
    18.             Importance = Importance.High,
    19.         };
    20.  
    21.         AndroidNotificationCenter.RegisterNotificationChannel(defaultNotificationChannel);
    22.  
    23.  
    24.         AndroidNotification notification = new AndroidNotification()
    25.         {
    26.             Title = "Test Notification!",
    27.             Text = notificationTexts[Random.Range(0, notificationTexts.Length)],
    28.             SmallIcon = "app_icon_small",
    29.             LargeIcon = "app_icon_large",
    30.             FireTime = System.DateTime.Now.AddSeconds(2),
    31.         };
    32.  
    33.         identifier = AndroidNotificationCenter.SendNotification(notification, "default_channel");
    34.  
    35.  
    36.         AndroidNotificationCenter.NotificationReceivedCallback receivedNotificationHandler = delegate (AndroidNotificationIntentData data)
    37.         {
    38.             var msg = "Notification received : " + data.Id + "\n";
    39.             msg += "\n Notification received: ";
    40.             msg += "\n .Title: " + data.Notification.Title;
    41.             msg += "\n .Body: " + data.Notification.Text;
    42.             msg += "\n .Channel: " + data.Channel;
    43.             Debug.Log(msg);
    44.         };
    45.  
    46.         AndroidNotificationCenter.OnNotificationReceived += receivedNotificationHandler;
    47.  
    48.         var notificationIntentData = AndroidNotificationCenter.GetLastNotificationIntent();
    49.  
    50.         if (notificationIntentData != null)
    51.         {
    52.             Debug.Log("App was opened with notification!");
    53.         }
    54.  
    55.     }
    56.  
    57.     private void OnApplicationPause(bool pause)
    58.     {
    59.  
    60.         if (AndroidNotificationCenter.CheckScheduledNotificationStatus(identifier) == NotificationStatus.Scheduled)
    61.         {
    62.             //If the player has left the game and the game is not running. Send them a new notification
    63.             AndroidNotification newNotification = new AndroidNotification()
    64.             {
    65.                 Title = "Reminder Notification!",
    66.                 Text = "You've paused Unity Royale!",
    67.                 SmallIcon = "app_icon_small",
    68.                 LargeIcon = "app_icon_large",
    69.                 FireTime = System.DateTime.Now
    70.             };
    71.  
    72.             // Replace the currently scheduled notification with a new notification.
    73.             AndroidNotificationCenter.UpdateScheduledNotification(identifier, newNotification, "default_channel");
    74.         }
    75.         else if (AndroidNotificationCenter.CheckScheduledNotificationStatus(identifier) == NotificationStatus.Delivered)
    76.         {
    77.             //Remove the notification from the status bar
    78.             //AndroidNotificationCenter.CancelNotification(identifier);
    79.         }
    80.         else if (AndroidNotificationCenter.CheckScheduledNotificationStatus(identifier) == NotificationStatus.Unknown)
    81.         {
    82.             AndroidNotification notification = new AndroidNotification()
    83.             {
    84.                 Title = "Test Notification!",
    85.                 Text = runtimeNotificationTexts[Random.Range(0, runtimeNotificationTexts.Length)],
    86.                 SmallIcon = "app_icon_small",
    87.                 LargeIcon = "app_icon_large",
    88.                 FireTime = System.DateTime.Now.AddSeconds(2),
    89.             };
    90.  
    91.             //Try sending it again
    92.             identifier = AndroidNotificationCenter.SendNotification(notification, "default_channel");
    93.         }
    94.  
    95.  
    96.     }
    The notifications are coming only when the game is running. Upon closing the app, I'm not receiving any notifications. Also, can someone explain why 90% of the times the "AndroidNotificationCenter.CheckScheduledNotificationStatus(identifier) == NotificationStatus.Unknown" is returning true? Why is the status unknown? Any reason?

    And also "AndroidNotificationCenter.CheckScheduledNotificationStatus(identifier) == NotificationStatus.Scheduled" this is never coming true though I'm coming to the homescreen before the said firetime. Any explanation please?
     
    Deleted User likes this.
  33. Extrawurst

    Extrawurst

    Joined:
    May 22, 2013
    Posts:
    43
    Hi @_Paulius,
    found a new issue with the android small icons in package version 1.0.3: They are broken when building a batch build with '-nographics' in 2019.2 and up. The small icon is then only rendered as a white square.

    One workaround I found is not use the unity editor to define the android icons at all and just put them in an AAR. then I can at least still build on my headless nographhics server. but this is weird limitation and should be fixed or documented, right?
     
  34. Molioo

    Molioo

    Joined:
    Mar 12, 2016
    Posts:
    7
    Sorry for really late response as we decided to not use Notifications for iOS for some time. Now when we decided to use it again, I see that even if "enable push notifications" in settings is disabled, I still get this warning. Is there anything I could do to prevent it?
     
  35. TheTall2338

    TheTall2338

    Joined:
    Jul 5, 2015
    Posts:
    15
    I am also having this issue. I'm hoping for a solution soon.
     
  36. DanilaVanilla

    DanilaVanilla

    Joined:
    Jul 4, 2016
    Posts:
    5
    Hello guys, i want to handle received notifications, on Android it's working, but on IOS not working.

    AndroidNotificationCenter.NotificationReceivedCallback receivedNotificationHandler = delegate { Game.UI.Show<ScreenMain>(); };
    AndroidNotificationCenter.OnNotificationReceived += receivedNotificationHandler;



    iOSNotificationCenter.OnRemoteNotificationReceived += notification =>
    {
    Game.UI.Show<ScreenMain>();
    };

    P.S. Sorry for my English.
     
  37. psynusoidal

    psynusoidal

    Joined:
    May 26, 2015
    Posts:
    14
    Hi @_Paulius

    Am I missing something, or does this plugin not currently expose a way to control Notification.Builder.setShowWhen()? I'd really like to be able to show a timestamp on my notifications on android.
     
  38. _Adriaan

    _Adriaan

    Joined:
    Nov 12, 2009
    Posts:
    481
    Hey @_Paulius! A while back you mentionned support for custom sounds was on its way. You have an updated prediction?
     
  39. Vasilis62

    Vasilis62

    Joined:
    Nov 2, 2018
    Posts:
    15
    I have come upon that problem as well. According to documentation, the only thing I can find is the UsesStopwatch property of the notification that just shows a timer, but nothing to show the timestamp.
     
  40. alebro_w

    alebro_w

    Joined:
    Oct 16, 2018
    Posts:
    10
    Hello,

    We have stumble upon some issues with notifications scheduling on Android when the app is updated from one version to another. A notification that is scheduled in version A and then triggered in version B will cause the app to crash (even when the game per se is not running). When the notification is triggered it will try to locate the small icon id, but it may not find it if the internal resource list has been updated.

    We get the following exceptions:
    Code (csharp):
    1.  
    2. Unable to load resource 0x7f050018 from pkg=<REDACTED>
    3.     android.content.res.Resources$NotFoundException
    4. FATAL EXCEPTION: main
    5.     Process: <REDACTED>, PID: 15278
    6.     android.app.RemoteServiceException: Bad notification posted from package <REDACTED>: Couldn't create icon: StatusBarIcon(icon=Icon(typ=RESOURCE pkg=<REDACTED> id=0x7f050018) visible user=0 )
    7.  

    Code (csharp):
    1. 2019-10-23 09:36:46.229 3397-3397/? E/Icon: Unable to load resource 0x7f050018 from pkg=<REDACTED>
    2.     android.content.res.Resources$NotFoundException: Drawable <REDACTED>:dimen/mintegral_video_common_alertview_contentview_minwidth with resource ID #0x7f050018
    3.     Caused by: android.content.res.Resources$NotFoundException: Resource "<REDACTED>:dimen/mintegral_video_common_alertview_contentview_minwidth" (7f050018) is not a Drawable (color or path): TypedValue{t=0x5/d=0xf001 a=2 r=0x7f050018}
    4.         at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:789)
    5.         at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:659)
    6.         at android.content.res.Resources.getDrawableForDensity(Resources.java:891)
    7.         at android.content.res.Resources.getDrawable(Resources.java:833)
    8.         at android.graphics.drawable.Icon.loadDrawableInner(Icon.java:323)
    9.         at android.graphics.drawable.Icon.loadDrawable(Icon.java:276)
    10.         at android.graphics.drawable.Icon.loadDrawableAsUser(Icon.java:387)
    11.         at com.android.systemui.statusbar.StatusBarIconView.getIcon(StatusBarIconView.java:352)
    12.         at com.android.systemui.statusbar.StatusBarIconView.getIcon(StatusBarIconView.java:336)
    13.         at com.android.systemui.statusbar.StatusBarIconView.updateDrawable(StatusBarIconView.java:314)
    14.         at com.android.systemui.statusbar.StatusBarIconView.set(StatusBarIconView.java:276)
    15.         at com.android.systemui.statusbar.NotificationData$Entry.createIcons(NotificationData.java:239)
    16.         at com.android.systemui.statusbar.phone.StatusBar.createNotificationViews(StatusBar.java:11091)
    17.         at com.android.systemui.statusbar.phone.StatusBar.addNotification(StatusBar.java:3381)
    18.         at com.android.systemui.statusbar.phone.StatusBar$31$2.run(StatusBar.java:9555)
    19.         at android.os.Handler.handleCallback(Handler.java:789)
    20.         at android.os.Handler.dispatchMessage(Handler.java:98)
    21.         at android.os.Looper.loop(Looper.java:164)
    22.         at android.app.ActivityThread.main(ActivityThread.java:6944)
    23.         at java.lang.reflect.Method.invoke(Native Method)
    24.         at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    25.         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
    26. 2019-10-23 09:36:46.258 15278-15278/<REDACTED> E/AndroidRuntime: FATAL EXCEPTION: main
    27.     Process: <REDACTED>, PID: 15278
    28.     android.app.RemoteServiceException: Bad notification posted from package <REDACTED>: Couldn't create icon: StatusBarIcon(icon=Icon(typ=RESOURCE pkg=<REDACTED> id=0x7f050018) visible user=0 )
    29.        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1881)
    30.        at android.os.Handler.dispatchMessage(Handler.java:105)
    31.        at android.os.Looper.loop(Looper.java:164)
    32.        at android.app.ActivityThread.main(ActivityThread.java:6944)
    33.        at java.lang.reflect.Method.invoke(Native Method)
    34.        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    35.        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

    In our case for instance, we included a new ad network to the app which caused the resource list to scramble. The resource id the notification tries to use now points to something else.

    I realize that this issue maybe is fairly common in any native Android apps as well, but it would be appreciated if something could be done on your end with the package if that is possible. Correct me if I'm wrong, but I suspect the resource id reference need to be delayed til the very last end when the notification is triggered, and not directly when the notification is scheduled. Is there anything we can do in the meantime to circumvent the issue?

    Thanks in advance
     
    Last edited: Nov 4, 2019
  41. FlyingSquirrels

    FlyingSquirrels

    Joined:
    Sep 18, 2015
    Posts:
    83
    Did you report this issue by any chance?
     
  42. VaidasM

    VaidasM

    Unity Technologies

    Joined:
    Jun 27, 2017
    Posts:
    41
    @psynusoidal @Vasilis62 the fix for the timestamp will be coming to the package shortly (preview 4 version)
     
  43. psynusoidal

    psynusoidal

    Joined:
    May 26, 2015
    Posts:
    14
    @VaidasM good news. much appreciated!
     
  44. Vasilis62

    Vasilis62

    Joined:
    Nov 2, 2018
    Posts:
    15
    @VaidasM That sounds great, thank you for communicating it with us!
     
  45. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    A new patch was just published:

    1.0.4-preview.4
    Fixes & Improvements:

    • [Android] Icon resources will now be queried when the notification is supposed to be triggered instead of when it's scheduled. This should fix crashes due to missing resources in cases where the app is updated after a notification is scheduled but before it's delivered.
    • [Android] Added the ShowTimestamp to AndroidNotification property to allow displaying timestamps on delivered notifications. The specific time stamp value can be overriden using 'AndroidNotification.CustomTimestamp' if it's not set the time at which the notification was delivered will be shown.
     
    alebro_w likes this.
  46. URoutine

    URoutine

    Joined:
    Nov 11, 2017
    Posts:
    4
    Hey, we implemented remote notifications using this snippet of code:

    Code (CSharp):
    1. void Start()
    2.     {
    3.         StartCoroutine(RequestAuthorization());
    4.         iOSNotificationCenter.OnRemoteNotificationReceived += notification =>
    5.         {
    6.             // When a remote notification is received, modify its contents and show it
    7.             // after 1 second.
    8.             var timeTrigger = new iOSNotificationTimeIntervalTrigger()
    9.             {
    10.                 TimeInterval = new TimeSpan(0, 0, 1),
    11.                 Repeats = false
    12.             };
    13.  
    14.             iOSNotification n = new iOSNotification()
    15.             {
    16.                 Title = "Remote : " + notification.Title,
    17.                 Body = "Remote : " + notification.Body,
    18.                 Subtitle = "Remote: " + notification.Subtitle,
    19.                 ShowInForeground = true,
    20.                 ForegroundPresentationOption = PresentationOption.Sound | PresentationOption.Alert | PresentationOption.Badge,
    21.                 CategoryIdentifier = notification.CategoryIdentifier,
    22.                 ThreadIdentifier = notification.ThreadIdentifier,
    23.                 Trigger = timeTrigger,
    24.             };
    25.             iOSNotificationCenter.ScheduleNotification(n);
    26.  
    27.             Debug.Log("Rescheduled remote notifications with id: " + notification.Identifier);
    28.         };
    29.     }
    30.  
    31.     IEnumerator RequestAuthorization()
    32.     {
    33.         Debug.Log("Starting coroutine");
    34.         using (var req = new AuthorizationRequest(AuthorizationOption.Alert | AuthorizationOption.Badge | AuthorizationOption.Sound, true))
    35.         {
    36.             while (!req.IsFinished)
    37.             {
    38.                 Debug.Log("Requesting..");
    39.                 yield return null;
    40.             }
    41.  
    42.             string res = "\n RequestAuthorization: \n";
    43.             res += "\n finished: " + req.IsFinished;
    44.             res += "\n granted :  " + req.Granted;
    45.             res += "\n error:  " + req.Error;
    46.             res += "\n deviceToken:  " + req.DeviceToken;
    47.             Debug.Log(res);
    48.         }
    49.     }
    But when using the deviceToken the request gives us back, we receive the following error on our push service:

    Request Id 884 : {"errorMessage":"Unregistered or expired token","channelType":"APNS","pushProviderStatusCode":"400","pushProviderError":"BadDeviceToken","pushProviderResponse":"{\"reason\":\"BadDeviceToken\"}"}

    Any idea why this happens? How can the token be unregistered when we just received it via callback)

    EDIT: Solved it on Friday. Apparently, when creating the certificate (sandbox and production in one) Apple didn't add the certificate to the sandbox part, which prevented us from testing notifications in a dev build.
     
    Last edited: Nov 11, 2019
  47. Egil-Sandfeld

    Egil-Sandfeld

    Joined:
    Oct 8, 2012
    Posts:
    72

    Perhaps you would want to update minimum Unity editor requirements in your OP, if 2019.3 is minimum for using the 1.0.4?

    Spent 2 hours figuring this out
     
  48. Egil-Sandfeld

    Egil-Sandfeld

    Joined:
    Oct 8, 2012
    Posts:
    72
    For others stuck with lower than 2019.3 versions, maybe this is useful:

    Managed to get the 1.0.4-preview5 onto a Unity 2019.2.12f1 project, by
    1. downloading 2019.3.0b
    2. creating a project
    3. Adding 1.0.4-preview5 package to the project
    4. Copy that package folder directly into the 2019.2.12 project's Assets folder
    5. Manually added small icon to Plugins/Android/res/drawable folder
    6. Built to Android
    Haven't tested iOS yet though
     
  49. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    266
    I'm getting an error with 1.0.3 and Unity 2019.2.13f1 when I call this:
    AndroidNotificationCenter.SendNotification

    the error:
    Code (CSharp):
    1.  
    2. [Lunar Mobile Console] Exception while invoking action 'Test Notify'
    3. java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Class.getName()' on a null object reference
    4. java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Class.getName()' on a null object reference
    5.     at com.unity3d.player.ReflectionHelper.getMethodID(Unknown Source:224)
    6.     at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    7.     at com.unity3d.player.UnityPlayer.c(Unknown Source:0)
    8.     at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
    9.     at android.os.Handler.dispatchMessage(Handler.java:103)
    10.     at android.os.Looper.loop(Looper.java:214)
    11.     at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
    12.   at UnityEngine._AndroidJNIHelper.GetMethodID (System.IntPtr jclass, System.String methodName, System.String signature, System.Boolean isStatic) [0x00041] in /Users/builduser/buildslave/unity/build/Modules/AndroidJNI/AndroidJava.cs:1396
    13.   at UnityEngine.AndroidJNIHelper.GetMethodID (System.IntPtr javaClass, System.String methodName, System.String signature, System.Boolean isStatic) [0x00005] in /Users/builduser/buildslave/unity/build/Modules/AndroidJNI/AndroidJNI.bindings.cs:61
    14.   at UnityEngine._AndroidJNIHelper.GetMethodID[ReturnType] (System.IntPtr jclass, System.String methodName, System.Object[] args, System.Boolean isStatic) [0x0000a] in /Users/builduser/buildslave/unity/build/Modules/AndroidJNI/AndroidJava.cs:1353
    15.   at UnityEngine.AndroidJNIHelper.GetMethodID[ReturnType] (System.IntPtr jclass, System.String methodName, System.Object[] args, System.Boolean isStatic) [0x00005] in /Users/builduser/buildslave/unity/build/Modules/AndroidJNI/AndroidJNI.bindings.cs:166
    16.   at UnityEngine.AndroidJavaObject._CallStatic[ReturnType] (System.String methodName, System.Object[] args) [0x0001d] in /Users/builduser/buildslave/unity/build/Modules/AndroidJNI/AndroidJava.cs:601
    17.   at UnityEngine.AndroidJavaObject.CallStatic[ReturnType] (System.String methodName, System.Object[] args) [0x00004] in /Users/builduser/buildslave/unity/build/Modules/AndroidJNI/AndroidJava.cs:318
    18.   at Unity.Notifications.Android.AndroidNotificationCenter.SendNotification (System.Int32 id, Unity.Notifications.Android.AndroidNotification notification, System.String channel) [0x00073] in /Users/edwon/Projects/Wormy/Library/PackageCache/com.unity.mobile.notifications@1.0.3/Runtime/Android/AndroidNotificationCenter.cs:872
    19.   at Unity.Notifications.Android.AndroidNotificationCenter.SendNotification (Unity.Notifications.Android.AndroidNotification notification, System.String channel) [0x0003e] in /Users/edwon/Projects/Wormy/Library/PackageCache/com.unity.mobile.notifications@1.0.3/Runtime/Android/AndroidNotificationCenter.cs:840
    20.   at Notifications.OnSubmitNotification (System.String title, System.String body, System.DateTime deliveryTime) [0x00039] in /Users/edwon/Projects/Wormy/Assets/00_Everything/Scripts/Notifications.cs:64
    21.   at Notifications.TestNotification () [0x0000e] in /Users/edwon/Projects/Wormy/Assets/00_Everything/Scripts/Notifications.cs:73
    22.   at Notifications.<Awake>b__5_0 () [0x00000] in /Users/edwon/Projects/Wormy/Assets/00_Everything/Scripts/Notifications.cs:27
    23.   at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
    24.   at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <319b5411003b47fbaceecace494b6f79>:0
    The error does not throw when I use the latest preview package (1.0.4 preview 5)
     
  50. vasanthbalaji

    vasanthbalaji

    Joined:
    Nov 15, 2014
    Posts:
    34
    @_Paulius
    im too getting same error when using package with 1.0.3 and unity 2019.2.14f1 as @edwon said
    preview package(1.0.4 preview 5) doesnt throw error and its working.