UnityNotifications Multiple choices for activity for notification Settings

I’m encountering an error with Unity notifications. Below are the AndroidManifest.xml and the logcat error message. I’ve tried searching for solutions, including configuring Proguard, but It’s not working

2023/07/23 01:32:10.684 28064 28221 Error UnityNotifications Multiple choices for activity for notifications, set activity explicitly in Notification Settings
2023/07/23 01:32:11.231 28064 28221 Error Unity AndroidJavaException: java.lang.RuntimeException: Failed to determine Activity to be opened when tapping notification
2023/07/23 01:32:11.231 28064 28221 Error Unity java.lang.RuntimeException: Failed to determine Activity to be opened when tapping notification
2023/07/23 01:32:11.231 28064 28221 Error Unity at com.unity.androidnotifications.UnityNotificationManager.initialize(UnityNotificationManager.java:118)
2023/07/23 01:32:11.231 28064 28221 Error Unity at com.unity.androidnotifications.UnityNotificationManager.getNotificationManagerImpl(UnityNotificationManager.java:141)
2023/07/23 01:32:11.231 28064 28221 Error Unity at com.unity3d.player.UnityPlayer.nativePause(Native Method)
2023/07/23 01:32:11.231 28064 28221 Error Unity at com.unity3d.player.UnityPlayer.-$$Nest$mnativePause(Unknown Source:0)
2023/07/23 01:32:11.231 28064 28221 Error Unity at com.unity3d.player.UnityPlayer$w.run(Unknown Source:2)
2023/07/23 01:32:11.231 28064 28221 Error Unity at android.os.Handler.handleCallback(Handler.java:942)
2023/07/23 01:32:11.231 28064 28221 Error Unity at android.os.Handler.dispatchMessage(Handler.java:99)
2023/07/23 01:32:11.231 28064 28221 Error Unity at android.os.Looper.loopOnce(Looper.java:226)
2023/07/23 01:32:11.231 28064 28221 Error Unity at android.os.Looper.loop(Looper.java:313)
2023/07/23 01:32:11.231 28064 28221 Error Unity at com.unity3d.player.UnityPlayer$C.run(Unknown Source:24)
2023/07/23 01:32:11.231 28064 28221 Error Unity at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0
2023/07/23 01:32:11.231 28064 28221 Error Unity

<?xml version="1.0" encoding="utf-8"?>

Proguard
-keep class com.unity.** { ;}
-keep class com.unity.androidnotifications.
* { ;}
-keepclassmembers class com.unity.androidnotifications.
* { ;}
-keepnames class com.unity.androidnotifications.
* { ;}
-keepclassmembernames class com.unity.androidnotifications.
* { *;}

I’m using
Unity 2022.3.0
Mobile Notifications 2.2.0
Just in case, I’m using firebase, too

1 Like

This is a new safeguard in latest version of the package. If your app has multiple activities and none of them is UnityPlayerActivity (happens when you extend Unity activity), we require you to explicitly set the activity in settings.
In previous version it would work fine for as long as app is running or in the background. But if you killed the app completely, your scheduled notifications would not arrive. Now we fail early so you know of the problem in advance.

Go to project settings and in the mobile notifications section provide the full class name for activity you want to open when notification is tapped.

4 Likes

For anyone who uses Firebase Cloud Messaging, set Custom Activity to “com.google.firebase.MessagingUnityPlayerActivity”

8 Likes

Thanks, that was the ticket. This was the last remaining issue when jumping from Unity 2021 to 2022.

2 Likes

Same problem i did but still not receiving

notification

Any other ideas? I have done this and it got the error below. I then manually updated the androidmanifest.xml to the content in the text document for firebase which overrides it and I get the same error. I can’t shift it.

I am using both Unity Mobile Notifications (for reading state etc) & Firebase Cloud Messaging (for sending and receving remote notifications)

AndroidJavaException: java.lang.RuntimeException: Failed to determine Activity to be opened when tapping notification
java.lang.RuntimeException: Failed to determine Activity to be opened when tapping notification
com.unity.androidnotifications.UnityNotificationManager.initialize(UnityNotificationManager.java:119)
com.unity.androidnotifications.UnityNotificationManager.getNotificationManagerImpl(UnityNotificationManager.java:142)
com.unity3d.player.UnityPlayer.nativeRender(Native Method)
com.unity3d.player.UnityPlayer.-$Nest$mnativeRender(Unknown Source:0)
com.unity3d.player.UnityPlayer$F$a.handleMessage(Unknown Source:122)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loopOnce(Looper.java:226)
android.os.Looper.loop(Looper.java:313)
com.unity3d.player.UnityPlayer$F.run(Unknown Source:24)
UnityEngine.AndroidJNISafe.CheckException () (at <00000000000000000000000000000000>:0)
UnityEngine.AndroidJNISafe.CallStaticObjectMethod (System.IntPtr clazz, System.IntPtr methodID, System.Span`1[T] args) (at <00000000000000000000000000000000>:0)
UnityEngine.AndroidJavaObject._CallStatic[ReturnType] (System.IntPtr methodID, System.Object[] args) (at <00000000000000000000000000000000>:0)
Unity.Notifications.Android.AndroidNotificationCenter.Initialize () (at <00000000000000000000000000000000>:0)
Unity.Notifications.NotificationCenter.Initialize (Unity.Notifications.NotificationCenterArgs args) (at <00000000000000000000000000000000>:0)
FirebasePushNotifications.InitialiseNotificationCenter () (at <00000000000000000000000000000000>:0)
FirebasePushNotifications.ConditionallyInitialise () (at <00000000000000000000000000000000>:0)

You must have messed something up in the manifest. Build apk, open it in Android Studio and check the final manifest. Most likely the metadata on custom activity is either not in there or is in the wrong place. Custom activity should be a meta-data element under application.

UPDATED: After pulling my hair out I noted I had a trailing space in the Custom Name definition. I’m going to need a beer. :slight_smile:

1 Like

亲测有效,谢谢老哥解决了困扰我好几天的问题! :partying_face: