Skip to content

Commit

Permalink
Merge pull request #992 from pratistha-05/develop
Browse files Browse the repository at this point in the history
fix for #990: runtime permission for alarm services in android 12+ devices
  • Loading branch information
federicoiosue authored Oct 4, 2024
2 parents 1e6124f + 2a8e30c commit a55d5e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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

0 comments on commit a55d5e5

Please sign in to comment.