Reputation: 678
If i sett HOUR=11 and MINUTE=00, it wont run at time 11:00 in my emulator, is something wrong here?:
Calendar cal = Calendar.getInstance();
PendingIntent pintent = PendingIntent.getService(this, 0, new Intent(this, MyService.class), 0);
cal.set(Calendar.MINUTE, MINUTE);
cal.set(Calendar.HOUR_OF_DAY, HOUR);
cal.add(Calendar.DAY_OF_YEAR,1);
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 86400000, pintent);
running = true;
Upvotes: 0
Views: 51
Reputation: 1325
This alarm will be work 11:00am..
Calendar cal = Calendar.getInstance();
Intent intent = new Intent(this, MyService.class);
PendingIntent penintent = PendingIntent.getService(this, 0, intent, 0);
AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
//Here I have set it to 11.00am
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 11);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
//set timer as a RTC Wakeup to alarm manager object
alarm.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY, penintent);
I suggest, try to use this solution.
Upvotes: 1