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

Handle exact alarms on android >= 14 #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sc-nick
Copy link

@sc-nick sc-nick commented Apr 17, 2024

SCHEDULE_EXACT_ALARM permission is denied by default on android 14 and higher

@sc-nick sc-nick self-assigned this Apr 18, 2024
@sc-nick sc-nick requested a review from dinitri April 18, 2024 11:36
@@ -90,6 +95,14 @@ public void initialize (CordovaInterface cordova, CordovaWebView webView) {
public void onResume (boolean multitasking) {
super.onResume(multitasking);
deviceready();

Context context = cordova.getActivity().getApplicationContext();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not use a runtime request permission instead of navigating to the settings page? Permissions like for pictures and Geo-location at the start of the app?


Context context = cordova.getActivity().getApplicationContext();
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !alarmManager.canScheduleExactAlarms()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !alarmManager.canScheduleExactAlarms()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && alarmManager.canScheduleExactAlarms()) {

?

Do we need the second condition?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alarmManager.canScheduleExactAlarms() checks whether the app has the appropriate SCHEDULE_EXACT_ALARM permission or not

AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !alarmManager.canScheduleExactAlarms()) {
Intent intent = new Intent(android.provider.Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM);
intent.setData(Uri.fromParts("package", context.getPackageName(), null));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
intent.setData(Uri.fromParts("package", context.getPackageName(), null));

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should bind the intent to the app

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

3 participants