Search Unity

Mobile Notification Preview Package

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

  1. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    @Bastienre4 seems that some Xiaomi or Huawei (afaik Honor uses the same Android UI as Huawei? ) utilize aggressive battery saver techniques which kill apps running in the background (I'm not really aware of any better solutions for this besides of what's suggested in that SF thread).
     
  2. Bastienre4

    Bastienre4

    Joined:
    Jul 8, 2014
    Posts:
    71
    @_Paulius Yes Honor is the same as Huawei I think. But isn't it possible to schedule a notification without keeping the app alive? I really see notifications as a way to drive player back in your game. Having to keep the app open (even in the background) kinda breaks the feature for me.
    Thanks for your answers :)
     
  3. jeric-aragon

    jeric-aragon

    Joined:
    Dec 11, 2015
    Posts:
    3
    Hi. Does this plugin support having a custom background? If not, will it be supported in the future? Thanks.
     
  4. lucast_unity

    lucast_unity

    Joined:
    Mar 20, 2018
    Posts:
    1
    Thanks for the package! It works for me but I got some crashes and exceptions on Samsung devices.
    The problem is only happened on Samsung device, other brands seems do not have this issue.

    The app will have fatal crash sometimes when the device is restarted while some notifications are scheduled.
    From the log below, seems the problem is there are too many alarms registered. As every time I schedule notifications, I will first do the following code to clear all current notifications but it still crash.

    Code (CSharp):
    1.             AndroidNotificationCenter.CancelAllDisplayedNotifications();
    2.             AndroidNotificationCenter.CancelAllScheduledNotifications();
    3.             AndroidNotificationCenter.CancelAllNotifications();
    Here is the log of the crash.


    Caused by java.lang.SecurityException: !@Too many alarms (500) registered from uid 10083
    at android.os.Parcel.createException(Parcel.java:1966)
    at android.os.Parcel.readException(Parcel.java:1934)
    at android.os.Parcel.readException(Parcel.java:1884)
    at android.app.IAlarmManager$Stub$Proxy.set(IAlarmManager.java:240)
    at android.app.AlarmManager.setImpl(AlarmManager.java:722)
    at android.app.AlarmManager.setExactAndAllowWhileIdle(AlarmManager.java:927)
    at com.unity.androidnotifications.UnityNotificationManager.scheduleNotificationIntentAlarm(UnityNotificationManager.java:403)
    at com.unity.androidnotifications.UnityNotificationRestartOnBootReceiver.onReceive(UnityNotificationRestartOnBootReceiver.java:41)
    at android.app.ActivityThread.handleReceiver(ActivityThread.java:3597)
    at android.app.ActivityThread.access$1300(ActivityThread.java:237)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1796)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7045)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)


    After I disabled the flag of Rescheduling Notifications on Device Restart for Android, seems the crash is fixed. However, this functionality is also disabled. And there is still a lot exceptions fired. Here is the log of the non-fatal exception.


    Non-fatal Exception: java.lang.Exception: AndroidJavaException : java.lang.SecurityException: !@Too many alarms (500) registered from uid 10077
    at android.os.Parcel.readException(android.os.Parcel)
    at android.os.Parcel.readException(android.os.Parcel)
    at android.app.IAlarmManager$Stub$Proxy.set(android.app.IAlarmManager$Stub$Proxy)
    at android.app.AlarmManager.setImpl(android.app.AlarmManager)
    at android.app.AlarmManager.setExactAndAllowWhileIdle(android.app.AlarmManager)
    at com.unity.androidnotifications.UnityNotificationManager.scheduleNotificationIntentAlarm(com.unity.androidnotifications.UnityNotificationManager)
    at com.unity.androidnotifications.UnityNotificationManager.scheduleNotificationIntent(com.unity.androidnotifications.UnityNotificationManager)
    at com.unity3d.player.UnityPlayer.nativePause(com.unity3d.player.UnityPlayer)
    at com.unity3d.player.UnityPlayer.l(com.unity3d.player.UnityPlayer)
    at com.unity3d.player.UnityPlayer$22.run(com.unity3d.player.UnityPlayer$22)
    at android.os.Handler.handleCallback(android.os.Handler)
    at android.os.Handler.dispatchMessage(android.os.Handler)
    at android.os.Looper.loop(android.os.Looper)
    at com.unity3d.player.UnityPlayer$e.run(com.unity3d.player.UnityPlayer$e)
    at UnityEngine.AndroidJNISafe.CheckException(UnityEngine.AndroidJNISafe)
    at UnityEngine.AndroidJavaObject._Call(UnityEngine.AndroidJavaObject)
    at Unity.Notifications.Android.AndroidNotificationCenter.SendNotification(Unity.Notifications.Android.AndroidNotificationCenter)
    at Unity.Notifications.Android.AndroidNotificationCenter.SendNotification(Unity.Notifications.Android.AndroidNotificationCenter)
    at AndroidLocalNotificationManager.ScheduleNotifications(CDH.AndroidLocalNotificationManager)


    Anyone also has this crash? Anything I missed to avoid these issues?
     
    Last edited: May 28, 2019
  5. Astro75

    Astro75

    Joined:
    Dec 18, 2014
    Posts:
    45
    We have a bug with Mobile Notifications package.
    When user clicks on a notification, app does NOT open.
    This is because we use non-default main activity (required by Firebase FCM plugin)
    Please fix this.
     
  6. Livealot

    Livealot

    Joined:
    Sep 2, 2013
    Posts:
    109
    Has anyone tried large icons yet? I see where to add them on Android in the Notification Settings, but I'm not sure where large icons show up in Android 9. I only see the small icon in all of the device UI. Bonus points for a screenshot!
     
  7. Livealot

    Livealot

    Joined:
    Sep 2, 2013
    Posts:
    109
    My other newb question is where do you change a notification from one-time to repeatable? It's the first bullet mentioned in the product but I see nothing in the API or demo app that describes the difference
    • Schedule notifications with Time, Calendar or a Location(only iOS) triggers (repeatable or one time).
     
  8. Astro75

    Astro75

    Joined:
    Dec 18, 2014
    Posts:
    45
    Is this forum thread a good place to report my bug with Mobile Notification Package? Or should I use unity bug reporter?
     
  9. Livealot

    Livealot

    Joined:
    Sep 2, 2013
    Posts:
    109
    Ah, I found them after realizing that the large icons do not need to be (and should not be) all white like the requirement for small icons. Since the default notification banner is also white, white large icons aren't a good idea.
     
  10. gili_unity

    gili_unity

    Joined:
    Jan 2, 2019
    Posts:
    9
    Why not have your own activity extend the Firebase messaging activity?
     
  11. gili_unity

    gili_unity

    Joined:
    Jan 2, 2019
    Posts:
    9
    We are experiencing some problems with the iOS local notifications:

    1. If the app is in the background and a local notification is clicked, iOSNotificationCenter.GetLastNotification() indeed returns the notification that was clicked.
    However, if the app is closed and a local notification is clicked to open the app, iOSNotificationCenter.GetLastNotification() always returns null.
    Why is that? How can we get the notification that opened the app in that case?

    2. If the app is in the foreground and a local notification is received, the "OnNotificationReceived" callback is not being called.
    After confirming the notification permission was granted, we call:
    iOSNotificationCenter.OnNotificationReceived += OnLocalNotificationReceived;
    (Either at the start of the app, or immediately after the permission was granted if the app launched without the permission)

    Here is the code for scheduling the notification:

    Code (CSharp):
    1. var userInfo = new Dictionary<string, string>()
    2. {
    3.     {"notification_type", "test"},
    4. };
    5. var timeTrigger = new iOSNotificationTimeIntervalTrigger()
    6. {
    7.     TimeInterval = new TimeSpan(0, 0, 5),
    8.     Repeats = false
    9. };
    10. iOSNotification notification = new iOSNotification()
    11. {
    12.     Title = "Test notification title",
    13.     Body = "Test notification text",
    14.     Data = JsonConvert.SerializeObject(userInfo),
    15.     Trigger = timeTrigger,
    16.     ShowInForeground = false
    17. };
    18. iOSNotificationCenter.ScheduleNotification(notification);
    I also tried using the options:
    Code (CSharp):
    1. ShowInForeground = true,
    2. ForegroundPresentationOption = PresentationOption.NotificationPresentationOptionAlert
    But it did not work, the notification wasn't displayed and the callback wasn't received.

    Why isn't the callback being called?

    3. Is there a way to clear the value in iOSNotificationCenter.GetLastNotification()?

    Thanks,
    Gili
     
    Last edited: May 28, 2019
  12. Astro75

    Astro75

    Joined:
    Dec 18, 2014
    Posts:
    45
    This would not help at all. Bug is not related to Firebase. Mobile Notifications plugin fails on any non-default main activity.
     
  13. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,468
    I am seeing this too.

    Using preview.21.
     
  14. tnbao91

    tnbao91

    Joined:
    Sep 5, 2013
    Posts:
    46
    I modified mobile notification jar lib for anyone who uses firebase and game not open when tapping the notification.

    Replace it in your project follow path inside aar

    Library/PackageCache/com.unity.mobile.notifications@1.0.0-preview.21/Runtime/Android/Plugins/Android/androidnotifications-release.aar
     

    Attached Files:

  15. navesanta

    navesanta

    Joined:
    Jul 2, 2018
    Posts:
    2
    [QUOTE = "_ Paulius、投稿:4154152、メンバー:653798"]私たちは、Unityから直接AndroidおよびiOS上でモバイル通知を管理できる新しいパッケージをPreviewリポジトリに公開しました。

    それはAndroid上でローカル通知を送信するためのサポートを追加します。iOSでは、NotificationServices API(しばらくの間Unityで利用可能でしたが廃止予定のiOS APIを使用しています)を置き換えることを意図しており、UserNotifications Frameworkを実装しています。

    AndroidとiOSの両方の主な機能は次のとおりです。
    • 時間、カレンダー、または場所(iOSのみ)のトリガー(繰り返し可能または1回限り)で通知をスケジュールします。
    • Android Oreo以上で通知チャンネルを管理します。
    • スケジュールされた通知をキャンセルして、それらの現在のステータスを追跡します(Android 6.0以降)。
    • カスタムアイコンを(Android上で)提供します。
    • プレゼンテーションオプションをカスタマイズする(iOSの場合)。
    • ローカルまたはプッシュ通知が配信されたときにトリガーされるカスタムC#コールバックを実装します(プッシュ通知は現在iOSでのみサポートされています)。
    • 通知をスレッドにグループ化します(iOS 12以降)。
    • アプリのアイコンバッジ番号を変更します。
    • Android 4.1以降(API 16)およびiOS 10以降をサポートしています。

    あなたはUnity Editorの中のPackage Managerウィンドウに行くことによってPreviewパッケージをダウンロードすることができます(パッケージは2018.3以降で利用可能です):
    • ウィンドウ上部の[詳細]ボタンをクリックして、[プレビューパッケージの表示]をクリックします。
    • リストに '' Mobile Notifications 'パッケージが表示されます。

    あるいは、これをPackages / manifest.jsonファイルに追加するだけです。

    [code = JavaScript] "依存関係":
    {
    ...
    "com.unity.mobile.notifications": "1.0.0-preview.13、
    ...
    }
    }[/コード]


    あなたはここで APIリファレンスといくつかの例を含むドキュメントを見つけることができます。

    また、同じAPIでAndroidとiOSの両方のデバイスに通知を送信できるようにする、高レベルのラッパーを実装するサンプルプロジェクトも作成しました。GitHubページで確認できます

    このパッケージはまだ開発中ですので、フィードバックや提案があればここに投稿してください。(あるいは、あなたが見つけたバグや問題を報告するためにUnityバグレポーターを使うこともできます)[/ QUOTE]
     
  16. navesanta

    navesanta

    Joined:
    Jul 2, 2018
    Posts:
    2
    モバイル通知プレビューパッケージについて

    どのようにして下記のデータを入手するのですか?

    notification.IntentData = "{\" title \ ":\" Notification 1 \ "、\" data \ ":\" 200 \ "}";
     
  17. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,468
    If you create a notification with a badge, how do you then clear the badge?
     
  18. srebolledo_unity

    srebolledo_unity

    Joined:
    Apr 25, 2018
    Posts:
    1
    Hi!
    I'm having the same issue that everyone that has a custom UnityActivity has, the application can send local notifications but I can't reopen the app from the notification.
    I was decompiling the aar and noticed that it will configure the intent using the Unty default one. I would love to use this plugin (I have everything already setup), but is let down not be able to configure which activity the notitifcation needs to open, so here is my request, can you provide a way to set that thing? Or even better, the sources for that aar file?
    Thanks in advance!
     
  19. TorLinn

    TorLinn

    Joined:
    Jan 6, 2018
    Posts:
    2
    Hello
    What could be the problem - all notification work as they should. But I can not change the color of the title and icons.
    Code (CSharp):
    1. _notification.Color = Color.green;
     
    lesinski likes this.
  20. tnbao91

    tnbao91

    Joined:
    Sep 5, 2013
    Posts:
    46
    you can use my tmp solution above
     
  21. angelkyriako

    angelkyriako

    Joined:
    May 21, 2013
    Posts:
    6
    Lukas-Labaj likes this.
  22. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    52
    I think it's worth to mention in this article Unity Mobile Notifications Package that this is not a plugin you need to install or import from GitHub but built in Unity tool which you can added from Package Manager, within Unity Editor. I spent some time before I found suggestion in the first post to modify "Packages/manifest.json" file manually.Thanks
     
  23. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    52
    I noticed that AndroidNotificationCenter.GetLastNotificationIntent() gets intent only if app was taken from soft pause (background). However, if app was opened with notification while it was closed, no intent is returned, is that intentional, bug or I am doing something wrong? Thanks
     
  24. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,468
    You can install from Package Manager. Just make sure to view preview packages.
     
  25. as5405as

    as5405as

    Joined:
    Aug 22, 2017
    Posts:
    3
    notificationManager.LocalNotificationDelivered
    notificationManager.LocalNotificationExpired

    those two event is not work
    How can I get CallBack fromNotification
     
  26. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    52
    That's what I am suggesting them to add to article, so anyone else, who will reach it, will know how to do that. I personally was googling how to implement notifications in Unity on Android platform and came across to that article without any instructions that package should be installed and how =)

    @as5405as I think too many things are not working in this package and I will better pay couple of buck to get relatively working solution. The biggest downside is that this package from Unity has no support or care.
     
  27. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    21
    Thank you! Now my notifications open the app (instead of doing nothing).
    It's a pretty annoying bug, since Firebase is very common in mobile apps. I hope it gets fixed soon.
     
  28. Telgemannen

    Telgemannen

    Joined:
    Jun 10, 2015
    Posts:
    10
    @_Paulius Re: @HomeInnovation 's question if it is possible to schedule notifications from a worker thread or when unity is paused: Is there really no way to schedule notifications while the application is paused? Are we supposed to pre-schedule notifications in case we need them, then update as appropriate (from worker threads)? Or is that also not supported? How are we then to send notifications without knowing about them beforehand? Because it can't just be me requiring this?
     
  29. Telgemannen

    Telgemannen

    Joined:
    Jun 10, 2015
    Posts:
    10
    Another question: Is UpdateScheduledNotification not implemented? I've tried it with 1.0.0.preview9 with unity 2018.2.18 and 1.0.0.preview21 with unity 2018.3.14 and I always get an androidjavaexception with the message "java.lang.NoSuchMethodError: no static method with name='checkIfPendingNotificationIsRegistered'"
     
  30. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    21
    Thanks!

    This still persists in v21.
    CancelAll() doesn't work if the app has been completely closed. It does work if the app was still open in the background.
    Cancel(int) one by one does.
     
    Last edited: Jun 21, 2019
  31. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,468
    @_Paulius please update the changelog for preview.23. Thanks.
     
  32. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    486
    It's available in the package...

     
    andymads likes this.
  33. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,468
    Can you confirm this is still the case in preview.23? It's not listed as fixed in the changelog. Thanks.
     
  34. aalexa13

    aalexa13

    Joined:
    Jan 6, 2015
    Posts:
    5
    Hi! Sorry for me English
    What can be wrong?
    I use GameNotificationsManager from NotificationsSamples. I can create and receive messages.
    But when I click on message, there are nothing hepens. App in not launching. App installed as apk with debug information (unity build and run)

    I am using firebase in the project.
    <activity android:name="com.google.firebase.MessagingUnityPlayerActivity"...

    Thanks!
     
    Last edited: Jun 24, 2019
  35. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    21
    It doesn't even seem to 100% work in v23.
     
  36. aalexa13

    aalexa13

    Joined:
    Jan 6, 2015
    Posts:
    5
    I made some research and found class AndroidNotificationCenter
    static bool Initialize()

                    //AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    AndroidJavaClass unityPlayer = new AndroidJavaClass("com.google.firebase.MessagingUnityPlayerActivity");
    AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");


    If I change UnityPlayer to MessagingUnityPlayerActivity, I got exception

    "java.lang.NoSuchFieldError: no \"Ljava/lang/Object;\" field \"currentActivity\" in class \"Lcom/google/firebase/MessagingUnityPlayerActivity;\" or its superclasses"


    How it can be possible? How it can be fixed?
     
  37. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    21
    Try it without Firebase and without "UnityPlayerActivity". They clash currently.
     
  38. aalexa13

    aalexa13

    Joined:
    Jan 6, 2015
    Posts:
    5
    Without firebase it will work. I have tried demo project, and it work without any problems.
    I want it working with firebase. Is it possible?
     
    Last edited: Jun 24, 2019
  39. viku_99

    viku_99

    Joined:
    Dec 14, 2016
    Posts:
    5
    Hi,
    The notification is not working when we killed app !
    suppose we have set the notification after 5 minutes , we navigate to home menu and after 5 minutes notification appear but if we killed the app then it is not working !!
    In project setting i have setup the custom notification icon but still it is not working !! it is displaying white square icon.

    Tested with Unity version 2018.4.1f
     
    akil-cmgt likes this.
  40. bekici

    bekici

    Joined:
    Nov 1, 2018
    Posts:
    4
    For those who gets this error: no static method with name='getNotificationManagerImpl'
    I think it is solved on preview.23. (Tested on Android 9 and Unity 2019.1.5f1)
     
  41. bekici

    bekici

    Joined:
    Nov 1, 2018
    Posts:
    4
    There is an interesting new issue on Preview.23 when I try on Lenovo TB3-710I, Android 5.1.

    When I use the gift emoji, the app crashes. The error log is as below:
    JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xf0

    This was fine on the version Preview.21.
     
  42. Nieles_GH

    Nieles_GH

    Joined:
    Jun 26, 2017
    Posts:
    54
    Thanks tnbao91!

    Can Unity please come up with a solution for this if possible?
    Firebase is quite a standard library to use for Android games.
    And even stronger I think you should be able to setup push notifications for Android using Firebase just like you can setup iOS push notifications in the settings. As far as I know, Firebase is kind of the standard Push notifications service for Android.
     
    tnbao91, aalexa13 and dbutrimov-wx like this.
  43. akil-cmgt

    akil-cmgt

    Joined:
    May 20, 2019
    Posts:
    2

    Same here.. Using OnePlus here.. what mobile are you using?
     
  44. akil-cmgt

    akil-cmgt

    Joined:
    May 20, 2019
    Posts:
    2
    Did you find a solution to this? @Bastienre4
     
  45. pixioco

    pixioco

    Joined:
    Feb 3, 2016
    Posts:
    2
    @_Paulius

    hello, AndroidNotificationCenter.SendNotification works fine when the app is opened/paused but no notification is received upon calling the same function in OnApplicationQuit(), when the app is closed. Device is Pixel2 with android version 9.0 . Any clue about this?
     
  46. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    21
    You have to schedule them before you close the app. Not during closing (e.g. OnApplicationFocus), before.
    It will never be possible to schedule notifications while the app isn't open.

    I just generate them every 10 seconds. This included wiping scheduled ones. Not elegant, but it works well. Generating them during OnApplicationFocus took too long and the app was closed before the notifications were generated.
    Now my players get reminded of the game exactly when and how often I want them to.
     
    Bastienre4 likes this.
  47. delebru

    delebru

    Joined:
    May 21, 2015
    Posts:
    2
    I just found that the enabling "Enable Push Notifications" for iOS gets automatically disabled every time I close and re-open Unity. But, if I also enable "Enable release environment for APS", the previous setting persists.

    Is this an expected behaviour?
     
  48. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    982
    It's not just those settings that get reset. I believe all settings get reset, since all my android settings were reset to defaults after closing and reopening Unity.
     
  49. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    982
    Also, after building with Cloud Build for iOS, my app asked for notification permission on app launch, while I specifically disabled this in the project settings.
    @_Paulius Please help!
     
  50. cometa93

    cometa93

    Joined:
    Mar 5, 2014
    Posts:
    24
    I'm joining the club with the extended UnityPlayerActivity in the Manifest. Please introduce the fix for this, like for example extrude the string for the class to the plugin settings.
    So if we want to use custom class we will check the checkbox and input our own extended classpath like:
    com.google.firebase.MessagingActivity for example.

    Currently, I've reviewed the plugin code and it has everywhere put just static strings like "com.unity3d.player.UnityPlayer" which is a very bad approach by the way.
     
unityunity