Its about a small android application that will take hours as input from user for every day of week and turn on / off blue tooth device accordingly for the respective day regardless of the “Date”. i.e the code should only check the day, hour and minute. i have used following code (for testing purpose for today i.e Friday) but it do not triggers the alarm.
//..........setting calender for MyAlarmService
Calendar cur_cal = new GregorianCalendar();
cur_cal.setTimeInMillis(System.currentTimeMillis());
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_YEAR, cur_cal.get(Calendar.DAY_OF_YEAR));
cal.set(Calendar.HOUR_OF_DAY, 11);
cal.set(Calendar.MINUTE, 5);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, cur_cal.get(Calendar.MILLISECOND));
cal.set(Calendar.DATE, cur_cal.get(Calendar.DATE));
cal.set(Calendar.MONTH, cur_cal.get(Calendar.MONTH));
// here it m setting the "Today"
cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
Intent myIntent = new Intent(AndroidAlarmService.this, MyAlarmService.class);
pendingIntent = PendingIntent.getService(AndroidAlarmService.this, 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
when i remove the statement
cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
The AlarmService triggers perfectly “Today” on the time specifed above i.e 11:05 AM
What am i doing wrong?
found a work around as follows.
and then i use separater alarm service for these days as follows