i want to check some url at 9:00 a.m everyday.But how can i do this? I did check some topic and article about AlarmManager and IntentService but i can't get together for my application , is there any example code or something ?Thank you..
Asked
Active
Viewed 4,871 times
1
-
1what is your problem with AlarmManager? – Naruto Uzumaki Sep 25 '14 at 21:11
-
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, Zamanlayici.class); intent.putExtra(ONE_TIME, Boolean.FALSE); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); //After after 5 seconds am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 10, pi); like this code, i can do this specific time between but i can't do this specific time – massaimara98 Sep 25 '14 at 21:14
-
So, create a `Calendar` object that is your specific time for the first event, and use a period of `INTERVAL_DAY` to have it recur every 24 hours. – CommonsWare Sep 25 '14 at 21:16
-
What is your calendar object? – Naruto Uzumaki Sep 25 '14 at 21:18
1 Answers
2
Try this:
/Create alarm manager
AlarmManager mAlarmManger = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
//Create pending intent & register it to your alarm notifier class
Intent intent = new Intent(this, AlarmReceiver_maandag_1e.class);
intent.putExtra("uur", "1e"); // if you want
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
//set timer you want alarm to work (here I have set it to 9.00)
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 9);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
//set that timer as a RTC Wakeup to alarm manager object
mAlarmManger .set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

Naruto Uzumaki
- 2,019
- 18
- 37
-
Warning: this approach does not take into account that `calendar` may be in the past. That will be the case for most of the day. You need to check to see if `calendar` is in the past, and if so, `add()` a day to it. – CommonsWare Sep 25 '14 at 21:41