Repeating Alarms not working below one minute - android

I have an App which doing stuff in a Service in background (also when Screen is swiched off). I start the service in an Activity with a repeating Alarm. Whatever I set below 60 seconds its ignored and the alarm comes exactly after 60 seconds.
I tested it with the emulator on Android 6.0, on a Samsung Galaxy with Android 6.0 and with a Sony Z3 with Android 5.1.1. On all the same. An ICS it worked perfectly. Isn't it possible anymore to repeate alarms below one minute?
If I set it to 120 seconds its working every 120 seconds. The same with 90 seconds ...
Intent i=new Intent(this, AppService.class);
i.putExtra(AppService.VOL_ALM, test_value));
PendingIntent pi = PendingIntent.getService(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pi);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 *time_in_seconds, pi);
EDIT:
I set up 60 s and left the phone work in background. Thats the result
Mai 15 17:08:01.803
Mai 15 17:10:39.213
Mai 15 17:25:39.317
Mai 15 17:40:39.259
Mai 15 17:55:39.255
Mai 15 18:10:39.292
Mai 15 18:25:39.255
Mai 15 18:40:39.238
what can I do to run the service at least every minute?

I have the solution. I always reset the alarm in the service, that works perfekt even down to 5s.
Intent i=new Intent(this, AppService.class);
i.putExtras(extraBundle); // read out inside the service
PendingIntent pi = PendingIntent.getService(this, 0, i, pi.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
// Remove old alarm
alarmManager.cancel(pi);
// Set new alarm
alarmManager.set(AlarmManager.RTC_WAKEUP, time, pi);

Related

not able to set alarm for more than 20 seconds

I had created alarm manager which invoke after 2 minutes which I want. But currently, i'm not able to set it more than 20 seconds. if I set for 20 seconds it returns output but if I set it for more than 20 I'm not able to set. I want to set it for 2 minutes. kindly help me.
I had added alarm fire code
AlarmManager manager = (AlarmManager) ContextGetter.getContext().getSystemService(Context.ALARM_SERVICE);
Intent intnt = new Intent(ContextGetter.getContext(), AlarmBroadcastReceiver.class);
intnt.setAction("com.demo.alarmEvent");
PendingIntent pending = PendingIntent.getBroadcast(ContextGetter.getContext(), 0, intnt, 0);
manager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ 30*1000, pending);
kindly help me
i want it set it only once.
I also tried with this one.
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intnt = new Intent(EnterSysNumber.getInstance(), AlarmReceiver.class);
intnt.setAction("com.demo.Enter_number");
PendingIntent pending = PendingIntent.getBroadcast(getApplicationContext(), 0, intnt, 0);
manager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 120000, pending);
In Android N you'll run into Doze mode. Doze is a deep sleep mode to save battery power. It will prevent your service to preserve battery power.
AlarmManager and using setExactAndAllowWhileIdle when in low-power idle modes this duration may be significantly longer, such as 15 minutes.. But this is NOT suggested for any Play Store app, you will kill your user's battery.

Alarm Manager not working properly for given interval

I need to call alarm Manger for the interval of every 2 minutes,I have implemented below code :-
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, downloader, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + (2 * 1000*60),(2 * 1000*60), pendingIntent);
I am facing problem that it is not working on exact interval of 2 minutes,means it is getting fired sometimes before one minute some time after 2 minutes
but i need to generate logs of this with the exact interval of 2 minutes,wheather phone is on wake up mode or in sleep mode.
I am using api level 23 for this functionality. please help....

Android - on sansung j5 Pending intent call does not work properly

I wrote a service to call pending intent after 1 minute
code:
AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarms.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
60 * 1000, pendingIntent);
this code works properly on all devices except samsung j5.Where it calls service after 5 minutes.
Please let me know what could be the possible reason for this issue.

My AlarmManager fires the alarm immediately

Though this question is repeated over and over here on SO, but non of the solutions are working, in the code below it should fire for the first time after 10 seconds from launching my activity, but it launch immediately. And I'm using FLAG_UPDATE_CURRENT so there's no past time to fire immediately as I'm not setting it at specific hour/minute/sec. Could you please bring my attention to what I'm missing.
I'm testing on Android 5.0 Targeting API 4.0+
compileSdkVersion 23
minSdkVersion 16
targetSdkVersion 23
Intent myIntent = new Intent(this, check.class);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC, 10000, (AlarmManager.INTERVAL_DAY / 8), pi);
And this is my check.class in AndroidManifest.xml
<receiver
android:name=".Check"
android:exported="false" />
10000 on the real time clock is always going to be in the past, so your alarm fires immediately. You want System.currentTimeMillis() + 10000 as the second argument in the setRepeating() call.
I would point out that setRepeating() is inexact as of KitKat, so the actual time the alarm fires may be off. If it matters, use the setExact() method instead, setting the alarm again for the desired interval each time it fires.

Android Alarm Manager repeating in not accurate time interval

I need my alarm to fire every 30 seconds - exactly as possible (+/-3 seconds). So I read this (official Android guide) and implemented this:
AlarmManager alarm = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, MyService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 30000, pendingIntent);
Result: The Alarm fires +/- every 50 seconds, which is not so much accurate if I gave interval of 30 seconds.
Where is the problem and what's going on here? In the documentation they say things about be careful with exact timers since cpu & battery consuming etc. but nevertheless still there is an option for exact if I want, and this is what I thought I implemented.
try this:
alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (2 * 1000), (30 * 1000), pendingIntent);
change delay 2 or up seconds for start alarm on firt time.

Categories

Resources