Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check to exact scheduling for notifications #659

Merged

Conversation

zdmitrynsk
Copy link
Contributor

@zdmitrynsk zdmitrynsk commented Dec 6, 2023

SCHEDULE_EXACT_ALARM, the permission introduced in Android 12 for apps to schedule exact alarms, is no longer being pre-granted to most newly installed apps targeting Android 13 and higher (will be set to denied by default).

And because the SCHEDULE_EXACT_ALARM permission is now denied by default and the permission grant process requires extra steps from users (the user must minimize the application and change the setting), developers are strongly encouraged to evaluate their use cases and determine if exact alarms still make sense for their use cases.

Now for Android devices with SDK greater than or equal to 33, a check has been added for the ability to schedule notifications via AlarmManager.setExactAndAllowWhileIdle(). If this is not possible, then the notification is sent via AlarmManager.set().

For AlarmManager.set() only needs android.permission.POST_NOTIFICATIONS. It can be easily obtained through a modal window using native.showPopup( "requestAppPermission", options )

More information:
https://developer.android.com/about/versions/14/changes/schedule-exact-alarms

… has been added for the ability to schedule notifications via AlarmManager.setExactAndAllowWhileIdle(). If this is not possible, then the notification is sent via AlarmManager.set().
@CLAassistant
Copy link

CLAassistant commented Dec 6, 2023

CLA assistant check
All committers have signed the CLA.

@zdmitrynsk zdmitrynsk changed the title Added check to send exact scheduling for notifications Added check to exact scheduling for notifications Dec 7, 2023
@Shchvova Shchvova merged commit 7975411 into coronalabs:master Mar 17, 2024
1 check passed
@AleCGames
Copy link

Great, thank you very much for this contribution. I still can't see anything in the documentation on how to implement these changes.
I have several professional apps where the user can select whether they want to get notifications every 30 min, 1 hour, and so on. All of these apps are experiencing crashes due to this permission.

@Shchvova
Copy link
Contributor

Shchvova commented Mar 18, 2024

Working on it. But idea is to request SCHEDULE_EXACT_ALARM permission

@AleCGames
Copy link

Hi @Shchvova
I've reviewed the documentation and they still haven't added how to check for exact alarms permission before scheduling notifications.

@zdmitrynsk
Copy link
Contributor Author

I don't really understand what you need, but if you need to check whether the required permission is granted, then I think you should use the following code solar2d:

system.getInfo("androidGrantedAppPermissions").

The changes I made here allow applications installed on Android 13 or higher to send notifications with at least the android.permission.POST_NOTIFICATIONS permission. Previously, in order to send notifications, you must have the SCHEDULE_EXACT_ALARM permission. That is, previously it was impossible to send a notification with only android.permission.POST_NOTIFICATIONS (on Android 13 or higher)

With the following code you can request android.permission.POST_NOTIFICATIONS:

local options =
{
appPermission = "android.permission.POST_NOTIFICATIONS",
urgency = "Critical",
listener = function(event)
end,
}
native.showPopup( "requestAppPermission", options )

@AleCGames
Copy link

Thank you for your explanation @zdmitrynsk
I got it now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants