У меня уже есть будильник, который срабатывает ежедневно, у которого есть FLAG_UPDATE_CURRENT
. Это журнал с консоли разработчика.
java.lang.SecurityException: [email protected] many alarms (500) registered from pid 32326 uid 10206
at android.os.Parcel.readException(Parcel.java:1540)
at android.os.Parcel.readException(Parcel.java:1493)
at android.app.IAlarmManager$Stub$Proxy.set(IAlarmManager.java:206)
at android.app.AlarmManager.setImpl(AlarmManager.java:428)
at android.app.AlarmManager.set(AlarmManager.java:215)
at com.google.firebase.iid.FirebaseInstanceIdService.zzagl(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceIdService.zzd(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceIdService.zza(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceIdService.zzm(Unknown Source)
at com.google.firebase.iid.zzb$2.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Я использую Firebase 9.6.1.
UPDATE:
public static void setAlarm(Context context, boolean isSet) {
try {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
boolean isWorking = (PendingIntent.getBroadcast(context,
SettingsActivity.REQUEST_CODE, intent, PendingIntent.FLAG_NO_CREATE) != null);
if (isSet && !isWorking) {
PendingIntent sender = PendingIntent.getBroadcast(context,
SettingsActivity.REQUEST_CODE, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR, 10);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, sender);
} else {
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
SettingsActivity.REQUEST_CODE, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
am.cancel(pendingIntent);
pendingIntent.cancel();
}
} catch (Exception e) {
Crashlytics.logException(e);
}
}