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

fix for #990: runtime permission for alarm services in android 12+ devices #992

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions omniNotes/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<uses-permission android:name="com.pushbullet.android.permission.SEND_MESSAGES" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.CAMERA"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.provider.Settings;
import android.text.TextUtils;
import android.widget.Toast;
import it.feio.android.omninotes.OmniNotes;
Expand All @@ -54,15 +56,31 @@ public static void addReminder(Context context, Note note) {

public static void addReminder(Context context, Note note, long reminder) {
if (DateUtils.isFuture(reminder)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { // Android 12 (API 31) and above
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

if (!alarmManager.canScheduleExactAlarms()) {
Intent intent = new Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM);
context.startActivity(intent);
return;
}
}

Intent intent = new Intent(context, AlarmReceiver.class);
intent.putExtra(INTENT_NOTE, ParcelableUtil.marshall(note));
PendingIntent sender = PendingIntent.getBroadcast(context, getRequestCode(note), intent,
immutablePendingIntentFlag(FLAG_CANCEL_CURRENT));
PendingIntent sender = PendingIntent.getBroadcast(
context,
getRequestCode(note),
intent,
immutablePendingIntentFlag(PendingIntent.FLAG_CANCEL_CURRENT)
);

AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.setExact(AlarmManager.RTC_WAKEUP, reminder, sender);
}
}


/**
* Checks if exists any reminder for given note
*/
Expand Down
Loading