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.
Related
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....
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);
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.
I have a problem with my alarm manager.
I want execute my code every 2 minutes so i made an alarm like this :
AlarmManager manager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 120000, pendingIntent);
But when i test this, my pendingIntent is executed every minutes.
If i start the application at 15:05:30
the first start of my pending intent is at : 15:06:00
and after every minutes.
I want to start when i start the application and after every 2 minutes.
Thx for your answers :)
I'm using the following code to schedule a service once a minute:
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), 60 * 1000, createFrequentUpdateIntent(context));
Everything works OK for some time, but after a few hours I stop receiving the update intent. I wake the phone up, wait a few minutes and nothing happens.
How can I solve this?