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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/android/LocalNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.util.Pair;
import android.view.View;

Expand Down Expand Up @@ -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?

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

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

cordova.getActivity().startActivity(intent);
}
}

/**
Expand Down