Hi team, as of Android 13, players are required to opt-in to notifications. Source. I’m looking for a simple way to request the POST_NOTIFICATIONSpermission.
I’ve tried using the permission class, as follows: Permission.RequestUserPermission("android.permission.POST_NOTIFICATIONS");
but this appears to trigger an infinite loop.
So far, I’ve only been able to request this permission by sending the player a notification from my personal server.
This infine loop happens when your target SDK is less than 33 (being fixed). You can only ask for this permission when you target API 33. When your app targets lower SDK, OS asks for permission automatically, your app can’t do that, best it can do is to open the settings page for itself.
If you wonder, new version of notifications package will be out very soon.
When installing 2.1.0 into Unity 2019 (via updating manifest.json) I get the following compile error:
Library/PackageCache/com.unity.mobile.notifications@2.1.0/Runtime/Android/NotificationPermission.cs(72,33): error CS0246: The type or namespace name 'PermissionCallbacks' could not be found (are you missing a using directive or an assembly reference?)/code]
Unity 2019 has reached it’s end of life, and the 2.1.0 version of package was released after that happened.
The 1.4.4 version should be compatible with 2019.
Hi @Aurimas-Cernius , I am using Unity Mobile Notification v2.1.0. I get issue once request permission for push notification, after request permission I get these log continuously and permission popup isn’t appear:
12-20 21:11:26.338 28039 28039 D Unity : onActivityResumed: com.unity3d.player.UnityPlayerActivity@1fd01db
12-20 21:11:26.338 28039 28039 I Unity : onResume
12-20 21:11:26.341 28039 28039 I Unity : onPause
…
I called this code:
Unity.Notifications.Android.PermissionRequest permissionRequest = new PermissionRequest();
It’s correct?
That should immediately solve the problem you see.
The real problem is that you app must target API 33 to be able to request for permission. If you target lower than 33, the permission request will pop automatically (handled by OS).
The endless pause-resume loop is a Unity bug, should be fixed in latest Unity versions.
Hello, was this issue fixed in Unity versions newer than 2020.3.41, so we can build using Target API level less than API 33 and be able to request for permission on Android 13 devices without any issue?
“This infine loop happens when your target SDK is less than 33 (being fixed).”
In this sentence you said being fixed, I thought anyway it is possible to build with target SDK level less than 33 and request permission on Android 13 if the infine loop bug fixed in newer Unity versions.
SO… Is this conclusion correct?
If we build with target API level less than 33 no matter which Unity version we use:
RequestPermission will not work because of loop issue.
Without RequestPermission there is no way to make notifications work.
The only way build the project using API level 33?
In my test, I have to set my app’s targetSdkVersion to 33 in order to ask for notification permission in Android 13 devices correctly. I’m using Unity 20210313 btw.
You are confusing two things here. The infinite loop was a Unity bug that has been fixed. But you still cannot ask for notification permission, if you target less than 33.
If your app targets <33, Android OS considers it an older app that does not know the permission even exists and ask for permission on apps behalf (and does not allow the app itself to ask for it).
Thank you for reply. As I understood from your explanation, if we target less than 33 we can’t ask for permission, but the Android 13 OS will detect app is using older target and will ask permission automatically, correct?
If this is correct, then currently for our build Android 13 OS not asking automatically for notifications permission after removing RequestPermission from the code. Do we need to add something to AndroidManifest or must other build setup be done to make this work? We are targeting API Level 31.