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
base: master
Are you sure you want to change the base?
Conversation
@@ -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(); |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intent.setData(Uri.fromParts("package", context.getPackageName(), null)); |
There was a problem hiding this comment.
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
SCHEDULE_EXACT_ALARM permission is denied by default on android 14 and higher