I’m struggling to find any documentation that talks about how an Android app can request permission to send local notifications. I have never used an Android device, but I assume it’s not just the wild west over there with any app sending any notification it wants.
I’m wanting to delay that request until a very specific time, not just have it pop up when the app starts or when the first notification gets sent. The package documentation only talks about that ability for iOS.
Do you know how to delay the notification permission request on Android?
Thanks
Android doesn’t require special permission for sending notifications and there’s no prompt like on iOS. Only special cases like full-screen notifications or changing notification settings require runtime permission and those can be requested with Android.Permission.
I think this has only been added in Android 13? You should be able to use Android.Permission.RequestUserPermission with the new permission string, though it’s not the new API that allows you show the reason why you’re requesting a permission.
Permission is only required on Android 13.
The API to request permission only works when app targets Android 13 and runs on it. If target SDK is lower, permission will be asked automatically by the OS.
You can request notification permission any time you want it by calling this Permission.
using UnityEngine;
using UnityEngine.Android;
public class RequestPermissions : MonoBehaviour
{
void Start()
{
if (!Permission.HasUserAuthorizedPermission("android.permission.POST_NOTIFICATIONS"))
{
Permission.RequestUserPermission("android.permission.POST_NOTIFICATIONS");
}
}
}
@Aurimas-Cernius we’re also trying to delay asking for permission on Android. On an Android 13 device, we’re getting asked on app start for this permission. We’re using the sample code, which we modified to not call RequestNotificationPermission() in GameNotificationsManager.Initialize(). We’re not seeing any setting related to this for Android in the project settings.
Any idea what could be causing the device to ask for permission?
If your target SDK is less than 33 (Android 13), then OS will ask for permission automatically on first launch. The code for asking permissions only works (and is required) when targeting 33.