Is there a possibility that the below code could fail due to the user denying the SCHEDULE_EXACT_ALARM permission after the permissions check and before the alarm is scheduled?
Note: I have never experienced this issue, this is purely an academic excersize.
public class MyService extends Service {
private void scheduleExactAlarm(Calendar alarmCalendar) {
if(getApplicationContext().checkSelfPermission(Manifest.permission.SCHEDULE_EXACT_ALARM) != PackageManager.PERMISSION_GRANTED) {
// handle permission not granted
return;
}
// can the user deny the permission here?
AlarmManager.AlarmClockInfo alarmInfo = // create alarmInfo with desired information
PendingIntent alarmOperation = // create alarmOperation with desired intent
AlarmManager alarmManager = getSystemService(AlarmManager.class);
alarmManager.setAlarmClock(alarmInfo, alarmOperation);
}
// the rest of the service implementation...
}
EDIT: I learned something new today. Special Permissions are not part of runtime permissions, so using checkSelfPermission(SCHEDULE_EXACT_ALARM) doesn't make sense. That being said, the question is intended to be broader than the specific permissions/operations used.