1

My device does not have a sim card or any network, Except wifi connection.

Now I am setting repeat alarm for daily which working fine when wifi is connected, But it does not trigger on time when wifi is not connected on the Android tablet.

val pendingIntent = PendingIntent.getBroadcast(context, requestCode, archiveIntent, PendingIntent.FLAG_CANCEL_CURRENT)
        val alarms = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
        alarms.cancel(pendingIntent)
        alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTime.timeInMillis, AlarmManager.INTERVAL_DAY, pendingIntent)

Here are my observations:

  1. Let say I set an alarm at 7:10 PM and when device time change to 7:10 PM it got the call as expected when wifi is connected all the time.

  2. Now the same scenario in which alarm set for 7:10 PM but when device time change to 7:10 PM but at that time wifi is not connected, Now after 7:11 I turn on my wifi on the device, Just after I connected wifi my previous set alarm got called in this case.

Can anyone know what could be reason alarm does not trigger in time when wifi not connected?

NOTE: In my alarm broadcast I am starting WorkManager which had a constraint that it should start only if there is wifi network connected, But I believe that WorkManager should not affect my alarm trigger.

Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
Herry
  • 7,037
  • 7
  • 50
  • 80

1 Answers1

1

Have a look at this answer

Its nothing to do with wifi, its the way you set it up, try with setRepeating instead of setInexactRepeating. The difference has explained nicely on above answer.

Edit

Eventually got it working after changing the flag to 0 like below

val pendingIntent = PendingIntent.getBroadcast(context, requestCode, archiveIntent, 0)

Passing 0 will bring any existing alarm back or create a new one.

ddassa
  • 309
  • 1
  • 6
  • I tried that but the results are same, unfortunately, Also I want to stick with setInexactRepeating event through it will add some drift in time that fine. – Herry Mar 11 '19 at 14:34
  • 1
    Have you tried with setting the flag to 0 like following code `val pendingIntent = PendingIntent.getBroadcast(context, requestCode, archiveIntent, 0)` – ddassa Mar 11 '19 at 14:57
  • Yup, Now it's got the trigger. Add this in your answer. – Herry Mar 11 '19 at 15:03
  • Good job. I added it to my answer so it will help someone in future. – ddassa Mar 11 '19 at 15:19