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. Nieles_GH

    Nieles_GH

    Joined:
    Jun 26, 2017
    Posts:
    57
    I was just wondering why my deviceToken was empty all the sudden. Then I also found out all my settings keep changing and it turned off Push Notification support!
     
  2. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,117
    Been trying to figure this out today. I believe I've fixed the settings not saving by going to
    Project Settings > Mobile Notification Settings > "cog menu" > Reset. After that the my notification settings started persisting between Unity restarts. I have to test this more to make sure it's actually working.

    I'm still figuring out why "Request Authorization on App Launch" not working as intended and asking for permission even when it is disabled.

    Also found an issue with scripting: AuthorizationRequest.Granted is always true, even when the permission was denied. So I can't use it and have to check if notifications are enabled or not by checking iOSNotificationSettings.

    Also the manual needs to be updated since there were changes to parameter naming such as AuthorizationOption.AuthorizationOptionAlert changed to AuthorizationOption.Alert.
     
    leynier41 likes this.
  3. Nieles_GH

    Nieles_GH

    Joined:
    Jun 26, 2017
    Posts:
    57
    Is it possible to retrieve the custom data from an ios push notification?
     
  4. Rajendra123R

    Rajendra123R

    Joined:
    Jul 13, 2015
    Posts:
    1
    when click on the notification game does not open
     
  5. Molioo

    Molioo

    Joined:
    Mar 12, 2016
    Posts:
    7
    Hey, I installed this package in my project, managed to prepare first notification but I have 16 errors from missing Tests references when I'm building for Android.

    Library\PackageCache\com.unity.mobile.notifications@1.0.2\Tests\Editor\PostprocessorTests.cs(4,7): error CS0246: The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?)

    Project build is successful but I can't hit play and test game in editor since I have those errors.
    Other errors are also from PostprocessorTests test script. Is there anything I did wrong or something I dont know about?
    I'm using Unity 2019.1.6f ,also checked on 2019.1.9f but it's the same.
     
    picolino0 likes this.
  6. devstyle

    devstyle

    Joined:
    Jan 29, 2015
    Posts:
    1
    I'm using Unity 2018.4.1f1
    Mobile Notifications Package 1.0.2

    build error for Android iOS PC.


    Assembly has reference to non-existent assembly 'UnityEngine.TestRunner' (Packages/com.unity.mobile.notifications/Tests/Editor/Unity.Notifications.Tests.asmdef)
     
    StefanoCecere, lesinski and picolino0 like this.
  7. Haukien

    Haukien

    Joined:
    Aug 20, 2014
    Posts:
    12
    We have the same issue. Unity 2018.4.3f1
     
    StefanoCecere, lesinski and picolino0 like this.
  8. Extrawurst

    Extrawurst

    Joined:
    May 22, 2013
    Posts:
    43
    I have the same issue with 1.0.2 again :(
     
    StefanoCecere likes this.
  9. Extrawurst

    Extrawurst

    Joined:
    May 22, 2013
    Posts:
    43
    I wondering the same, the documentation mentions the `Data` field but it is always empty and never contains anything and seems only to work with local notifications.

    @_Paulius is the Data field supposed to be filled with remote push custom data?
     
  10. PhiPham

    PhiPham

    Joined:
    Jul 12, 2019
    Posts:
    1
    I'm using Unity 2018.4.3f1, & always select option "Export Project" when build Android.
    I meet this error when using Mobile Notification Package: On Android >= 8.0, when click on a notification, the app does NOT open.

    I didn't use any custom UnityPlayerActivity, btw I see that Unity always create custom UnityPlayerActivity as <Package Name>.UnityPlayerActivity, and set it as Main Activity on AndroidManifest.xml

    <activity android:label="@String/app_name" android:theme="@android:style/Theme" android:screenOrientation="sensorPortrait" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false" android:name="com.my.game.package.UnityPlayerActivity">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
    </intent-filter>
    </activity>

    To pass over the issue, I modified Mobile Notification Package to get MainActivity (or any other activity that should be launched when click on Notification) from AndroidManifest.xml as below:

    Class UnityNotificationManager:
    UnityNotificationManager.png
    Class UnityNotificationRestartOn:
    UnityNotificationRestartOn.png

    AndroidManifest.xml:

    AndroidManifest.png

    BTW I think it will better if Mobile Notification Package can auto-detect main activity or add an option in setting for us, to input our Main Activity.

    I attached my androidnotifications-release.aar file for anyone need it. (Please rename it from .zip to .aar before use. I cannot upload .aar in this post)
     

    Attached Files:

    Qbit86 likes this.
  11. francismoy

    francismoy

    Joined:
    Jul 5, 2017
    Posts:
    46
    Hi, I’m experiencing the same errors as @Molioo :

    Library/PackageCache/com.unity.mobile.notifications@1.0.2/Tests/Editor/PostprocessorTests.cs(292,10): error CS0246: The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?)

    (The same message occurs with 'TestAttribute' and 'NUnit' together with 'Test').

    If I restart Unity, the messages are gone and I can continue working. But the messages reappear after making some actions (like making a build, for example).

    BTW I’m using the latest official Unity release (2019).
     
    Last edited: Jul 14, 2019
    mikapote likes this.
  12. rlewicki

    rlewicki

    Joined:
    Aug 28, 2018
    Posts:
    4
    I am experiencing same issue as @francismoy

    Further more, it is not only random error, when you actually try to make an Android build, the compilation process will fail due to error mentioned by @francismoy

    Can we please have any ETA on that fix?
     
  13. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    513
    +1, reverted back to previous (b 23) version...
     
  14. rtrypuchuuuge

    rtrypuchuuuge

    Joined:
    May 14, 2019
    Posts:
    9
    +1 same issue
     
  15. Lukas-Labaj

    Lukas-Labaj

    Joined:
    Nov 22, 2012
    Posts:
    36
    Last edited: Jul 16, 2019
  16. Extrawurst

    Extrawurst

    Joined:
    May 22, 2013
    Posts:
    43
    Why don't you use
    Code (csharp):
    1. UnityPlayer.currentActivity
    in the java code for that?
     
  17. Extrawurst

    Extrawurst

    Joined:
    May 22, 2013
    Posts:
    43
    So thanks to a friend I now know how to access custom data from remote notifications. custom data has to be in the key exactly named 'data' (in case of APNS next to the app key in the payload) AND it has to be a string, it cannot be a real JSON object. Thanks for documenting this... NOT :D
     
    Nieles_GH likes this.
  18. francismoy

    francismoy

    Joined:
    Jul 5, 2017
    Posts:
    46
    In my case, I can make Android builds without problem, but it fails when making iOS builds... As @PixelEnvision I have reverted back to b23 version, and now I can make iOS builds and the errors won't show up any more.
     
  19. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    369
    Hi guys and @_Paulius

    Any way to retrieve on iOS the userInfo dictionary from a push notification ? Because the plugin is hardcoded for find the field "data" in userinfo dictionary ?
    Legacy API allows that but not the new package :/

    Thanks
     
  20. mikapote

    mikapote

    Joined:
    Oct 24, 2018
    Posts:
    28
    I have the exact same issue as @PixelEnvision. I'd say it's a critical bug, forcing the user to restart Unity after each build.
     
  21. StefanoCecere

    StefanoCecere

    Joined:
    Jun 10, 2011
    Posts:
    210
    i could SOLVE the "Assembly has reference to non-existent assembly 'UnityEngine.TestRunner' (Packages/com.unity.mobile.notifications/Tests/Editor/Unity.Notifications.Tests.asmdef)" error installing the preview package com.unity.test-framework 0.0.4-preview
     
    Last edited: Jul 23, 2019
  22. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    1.0.3-preview was just published:

    Fixes:
    • Fixed an issue with NUnit Test assemblies not being detected correctly which caused exceptions to be thrown in the editor.

    • [Android] 1165178: An Android JAVA exception should no longer be thrown when attempting to schedule more than 500 notifications on Samsung devices. Samsung seems to impose a fixed limit of concurrent alarms. Now if this limit is reached all attempts to schedule new notifications will be ignored until the currently scheduled ones are triggered or manually cancelled.

    • [1114987] Reopening the project should no longer override Mobile Notification Settings.

    • [iOS] Fixed an issue with `iOSNotification.data` not being set correctly for remote notifications if the data field is not a string. It will now return a full JSON string for the data field.

    • [Android] Notifications cancelled using CancelScheduledNotification or CancelAllScheduledNotifications should no longer be recreated on device restart if the device is restarted before the time they were supposed to be triggered.
    Changes & Improvements:
    • [Android] Added an option to override the Android Android app activity which should be opened when a notification is clicked. By default the main activity assigned to the UnityPlayer Java class will be used.

    • Exposed notification settings (previously only accessible in UI) in a public Editor API (see the Unity.Notifications.UnityNotificationSettings) class.

    • Increased the minimum requirements to Android 4.4 (API 19)
     
    Nieles_GH likes this.
  23. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    369
    @_Paulius

    Hi,

    I have a problem on iOS, my app keeps his notification counter even if I call

    Code (CSharp):
    1.                iOSNotificationCenter.RemoveAllDeliveredNotifications();
    2.                 iOSNotificationCenter.RemoveAllScheduledNotifications();
    Any advice ?

    Thanks

    [EDIT]
    Badge can be controlled from iOSNotificationCenter.ApplicationBadge.
    Doc need to be updated to inform user that RemoveAllDeliveredNotifications doesn't manage badge like in old API
     
    Last edited: Jul 25, 2019
    joseibanez likes this.
  24. ajon542

    ajon542

    Joined:
    Oct 22, 2013
    Posts:
    25
    Unfortunately, even with the 1.0.3-preview package the NotificationSettings keep getting cleared if you delete the Library directory and reopen Unity.
     
  25. ajon542

    ajon542

    Joined:
    Oct 22, 2013
    Posts:
    25
    This doesn't appear to be fixed in 1.0.3-preview. I added some comments at the end of the ticket. When can we expect a fix for this?
    I could potentially work around this (untried/untested) for the time being by overwriting the NotificationSettings.asset with a known correct one during the build process.
     
  26. Deleted User

    Deleted User

    Guest

    hello, we have one problem about the repeat notification on ios, now only support repeate every day. how to do if we want to repeat every 7 days or other days on ios platform?
     
  27. CalaveraX

    CalaveraX

    Joined:
    Jul 11, 2013
    Posts:
    143
    I'm having the same issue.... Even when i restarted the editor, reimported the package manually, version 1.0.0-preview.21 / version1.0.2 / version 1.0.3preview
    closed the project, deleted library folder and reimported all... Still having missing assemblys.
    I really dont know whan else to do.
    Help would be really appreciated!
     

    Attached Files:

  28. ajon542

    ajon542

    Joined:
    Oct 22, 2013
    Posts:
    25
    When you say you "Increased the minimum requirements to Android 4.4 (API 19)", but I'm now unable to run on anything less than API 24. In AndroidNotificationCenter.cs, the call into native java is returning null:

    Code (CSharp):
    1. CallStatic<AndroidJavaObject>("getNotificationManagerImpl", context, activity);
    Everything works fine for API >= 24
     
    kactus223 likes this.
  29. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    @ajon542 just published "com.unity.mobile.notifications" : "1.0.3-preview.3" it has a fix for pre API 24 Android initialisation settings should no longer disappear when reimporting the project. Seems that this was a different issue from the one before, the settings provider was attempting to load the settings assets before the asset database was fully built in which case it failed to find it.

     
    mikapote, kactus223 and ajon542 like this.
  30. motorious

    motorious

    Joined:
    Jun 25, 2016
    Posts:
    11
    I tried the option (I set it to "com.google.firebase.MessagingUnityPlayerActivity"), but tapping the notification still doesn't do anything. I filed issue 1173038, with an empty test project attached.
     
  31. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    @motorious yes, seems that the custom activity string wasn't written to the manifest correctly in some cases.. This should be fixed in `com.unity.mobile.notifications@1.0.3-preview.4` (it now works fine with the project from 1173038).
     
  32. mikapote

    mikapote

    Joined:
    Oct 24, 2018
    Posts:
    28
    I've just updated Unity to 2019.2f, and I have a new error preventing me from building on the device:

    IL2CPP error for method 'System.Void Unity.Notifications.Android.AndroidNotificationCenter::RegisterNotificationChannel(Unity.Notifications.Android.AndroidNotificationChannel)' in AndroidNotificationCenter.cs:645
    Additional information: SafeArray element type Int64 is not supported.

    I've tried building with both 1.0.3-preview.3 and 1.0.3-preview.4.
    Anyone else has the same issue?
     
    MileSplit, segant and nolifeYoshi like this.
  33. nolifeYoshi

    nolifeYoshi

    Joined:
    Jan 20, 2015
    Posts:
    2
    The same.
     
  34. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    Same
     
  35. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    MileSplit and TextusGames like this.
  36. Sal_Dev

    Sal_Dev

    Joined:
    Nov 4, 2015
    Posts:
    6
    Hi,
    updating from unity 2019.1.11f1. to 2019.2.0f1 we see following error, when compiling to android APK/bundle

    IL2CPP error for method 'System.Void Unity.Notifications.Android.AndroidNotificationCenter::RegisterNotificationChannel(Unity.Notifications.Android.AndroidNotificationChannel)' in assembly 'E:\UnityProject\Temp\StagingArea\assets\bin\Data\Managed\Unity.Notifications.Android.dll'
    Additional information: SafeArray element type Int64 is not supported.

    this error is not showing up on 2019.1.11f1.

    we've tried both package versions:
    com.unity.mobile.notifications": "1.0.2"
    "com.unity.mobile.notifications": "1.0.0-preview.23",
    "com.unity.mobile.notifications": "1.0.3-preview.4"



    working on windows building for android with SDK and NDK embedded within unity. targeting Armv7 & Armv64
    we also tried NDK comes with 2019.1.11f1 , 2019.1.10f1 , no lucj

    please help :(
     
  37. Sal_Dev

    Sal_Dev

    Joined:
    Nov 4, 2015
    Posts:
    6
    Sorry for the duplicated report! missed prev posts,
    but yeah please if possible disable custom vibration till it fixed (better than nothing) We have important release with 2019.2, that just waiting to pass this compilation issue

    Thank you
     
  38. Flying_Space_Turtle

    Flying_Space_Turtle

    Joined:
    May 23, 2019
    Posts:
    4
    Hi, I'm using
    void Start()
    {
    var c = new AndroidNotificationChannel()
    {
    Id = "channel_id",
    Name = "Default Channel",
    Importance = Importance.High,
    Description = "Generic notifications",
    };
    AndroidNotificationCenter.RegisterNotificationChannel(c);
    var notification = new AndroidNotification();
    notification.Title = "Alfred";
    notification.Text = "Come see me. Don't keep me waiting long.";
    notification.FireTime = System.DateTime.Now.AddMinutes(300);

    AndroidNotificationCenter.SendNotification(notification, "channel_id");
    }

    I attached the script to a Game Object on the first Scene of my project, and the notification pops up, but like 6 of the same one. I don't see why it's firing off multiple. Or is there some other place I should be putting this script?
     
  39. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    163
    How can I see or get the 1.0.3+ versions?
    In the manager I can only see 1.0.2 and below, including all the preview versions. No 1.0.3 though (and I'd like to have that iOS fix).
    Changing the manifest.json manually results in some package not found error. Is it maybe only available on Git or so?
     
  40. nolifeYoshi

    nolifeYoshi

    Joined:
    Jan 20, 2015
    Posts:
    2
    May be you need to try it in new Unity? I use Unity version 2019.2.0f1 and there is the Mobile Notifications preview.4 - 1.0.3. It is located in the Package Manager.
     
  41. henti

    henti

    Joined:
    Mar 30, 2014
    Posts:
    1
    Hi Sal_Dev, I'm having the same exact issue, have you found a solution since then?

    Balazs
     
  42. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    Waiting for Paulius to fix it. He is the solution.
     
  43. Danoli3

    Danoli3

    Joined:
    Sep 12, 2017
    Posts:
    14
    Getting quite a lot of crashes on preview 1.0.3 preview 4: Unity 2018.4.5 LTS

    Code (CSharp):
    1. Broadcast of Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 cmp=com.nbcuni.usie.fftakedown/com.unity.androidnotifications.UnityNotificationRestartOnBootReceiver (has extras) }, InvisibleToUser
    2. com.unity.androidnotifications.UnityNotificationRestartOnBootReceiver
    Code (CSharp):
    1. "main" prio=5 tid=1 Native
    2.   | group="main" sCount=1 dsCount=0 flags=1 obj=0x7274c5f8 self=0xad935000
    3.   | sysTid=8354 nice=0 cgrp=bg_non_interactive sched=0/0 handle=0xb19b44a8
    4.   | state=S schedstat=( 28328141676 4130293098 83645 ) utm=1964 stm=867 core=4 HZ=100
    5.   | stack=0xbe04b000-0xbe04d000 stackSize=8MB
    6.   | held mutexes=
    7.   #00  pc 0000000000018e58  /system/lib/libc.so (syscall+28)
    8.   #01  pc 00000000000b395d  /system/lib/libart.so (_ZN3art17ConditionVariable16WaitHoldingLocksEPNS_6ThreadE+88)
    9.   #02  pc 00000000003bcecb  /system/lib/libart.so (_ZN3artL12GoToRunnableEPNS_6ThreadE+306)
    10.   #03  pc 00000000003bcd69  /system/lib/libart.so (_ZN3art12JniMethodEndEjPNS_6ThreadE+8)
    11.   #04  pc 00000000007e5ba1  /system/framework/arm/boot-framework.oat (Java_android_os_BinderProxy_transactNative__ILandroid_os_Parcel_2Landroid_os_Parcel_2I+144)
    12.   at android.os.BinderProxy.transactNative (Native method)
    13.   at android.os.BinderProxy.transact (Binder.java:748)
    14.   at android.app.IActivityManager$Stub$Proxy.getIntentSender (IActivityManager.java:5594)
    15.   at android.app.PendingIntent.getBroadcastAsUser (PendingIntent.java:563)
    16.   at android.app.PendingIntent.getBroadcast (PendingIntent.java:546)
    17.   at com.unity.androidnotifications.UnityNotificationManager.prepareNotificationIntent (UnityNotificationManager.java:381)
    18.   at com.unity.androidnotifications.UnityNotificationRestartOnBootReceiver.onReceive (UnityNotificationRestartOnBootReceiver.java:40)
    19.   at android.app.ActivityThread.handleReceiver (ActivityThread.java:3350)
    20.   at android.app.ActivityThread.-wrap17 (ActivityThread.java)
    21.   at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1725)
    22.   at android.os.Handler.dispatchMessage (Handler.java:105)
    23.   at android.os.Looper.loop (Looper.java:164)
    24.   at android.app.ActivityThread.main (ActivityThread.java:6694)
    25.   at java.lang.reflect.Method.invoke (Native method)
    26.   at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:240)
    27.   at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:769)
     
    Last edited: Aug 6, 2019
  44. Danoli3

    Danoli3

    Joined:
    Sep 12, 2017
    Posts:
    14
    Is it possible to Expose the AndroidNotificationCenter and iOSNotifictionCenter Initialize function so we can actually call it ourselves and check if it works. I'm getting thousands of errors from Android 5/6 with 1.0.3 preview 4. Unity 2018.4.5 LTS

    Code (CSharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object.
    3.   at Unity.Notifications.Android.AndroidNotificationCenter.Initialize () (at <00000000000000000000000000000000>:0)
    4.   at Unity.Notifications.Android.AndroidNotificationCenter.CancelAllScheduledNotifications () (at <00000000000000000000000000000000>:0)
    5.   at Unity.Notifications.Android.AndroidNotificationCenter.CancelAllNotifications () (at <00000000000000000000000000000000>:0)
    6.   at DNotifications.OnApplicationFocus (System.Boolean focus) (at <00000000000000000000000000000000>:0)
    7.   at Main.OnApplicationFocus (System.Boolean focus) (at <00000000000000000000000000000000>:0)
    8.  
     
  45. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
  46. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
  47. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    429
    Same
     
  48. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    1.0.3-preview.5 was just published, fixes and improvements:
    • [Android] Added a temporary fix for an IL2CPP compilation issue on Unity 2019.2 and above
    • [iOS] The notification returned by `iOSNotificationCenter.GetLastRespondedNotification()` is now cleared each time the app is moved to the background and not only when the app is fully terminated. Now it should only return the notification used to open the app or the last notification activated by the user while the app was running in the foreground.
    • [iOS] Turning on `Enable Push Notifications` will add the `remote-notification ` setting to `UIBackgroundModes` array in the app's `info.plist` file.
    @Flying_Space_Turtle I haven't seen this happening. Could you submit a bug report with your project and list the devices/Android version you've tested on?

    @drallcom3 that's strange it should be shown on all 2018.4 and all version above if 'Advanced -> Show Preview Packages` is enabled in the Package Manager.

    @Danoli3 I've made Initialize public as well, however I've tested it with 6.0.1 and 4.4 and it seems to work fine. There was an issue with broken initialisation on all pre API 24 devices in the initial build of `1.0.3-preview.` but it should have been fixed in preview.4).
     
    mikapote, nolifeYoshi and TextusGames like this.
  49. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    429
    There can i download it?
     
  50. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    @TextusGames It should be available in the package manager, however it seems that it's taking a while for it to appear in the public repository (usually it didn't take more than a few minutes in the past for a new version to become visible in the UI in the after it was published).

    Edit: it should be already visible in package manager.
     
    Last edited: Aug 6, 2019