0

I am using the following code to set a repeating alarm in android to trigger at every 12am but it not getting trigger even at one. I need this alarm to trigger from next day 12 am hence I added one date in calendar object.

Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.set(Calendar.HOUR_OF_DAY, 00);
        calendar.set(Calendar.MINUTE,00);
        calendar.set(Calendar.SECOND,00);

        calendar.add(Calendar.DATE,1);
        Utils.printLog("date from repeating alarm "+calendar.getTime());
        Intent startIntent = new Intent(context, RepeatingAlarmReceiver.class);
        PendingIntent startPIntent = PendingIntent.getBroadcast(context, 15, startIntent, 0);
        AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        if (alarmMgr != null) {
            alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY, startPIntent);
        }

I tested by breakpoint and found that alarmMgr is not null on setting it. Also the RepeatingAlarmReceiver.class is working.

Umar Ata
  • 4,170
  • 3
  • 23
  • 35
  • Do not use `setRepeating` . See https://stackoverflow.com/a/47651310/4168607. Set Exact Alarm each time set alarm for next event . – ADM Apr 22 '19 at 11:46
  • Even if you get it successful on emulator, it will not work in real world as 99% operating systems are MIUI, OxygenOS, ColorOs, FuntouchOs all are chinese modified ROMs, never allows to run it – sandhya sasane Apr 22 '19 at 16:29
  • i had a problem like this. i set an intent filter in manifest and called Intent intent = new Intent("com.mypackage.MY_ACTION); then intent.setClass(context, RepeatingAlarmReceiver.class); it worked when i set an action in intent filter and made intent like that – JRowan Apr 22 '19 at 19:35
  • https://github.com/copypasteearth/Powerball-MegaMillions/blob/master/app/src/main/java/powerball/apps/jacs/powerball/AlarmSettingManager.java – JRowan Apr 22 '19 at 19:38
  • @JRowan unfortunately my broadcast receiver has no problems, it works perfectly on calling by other ways. Main problem is alarm is not triggering. – Umar Ata Apr 23 '19 at 15:13

0 Answers0