我正在创建一个选择了某些特定日期的警报。我希望在那些工作日的某个时间点重复警报。But the alarm is fired as soon as i create an alarm, when past and future week days are selected.
例如,将今天视为“星期三”,如果我选择星期二和星期四,则会在创建它时触发警报。但它应该分别在即将到来的星期二和明天触发。我无法在以下代码中找到错误。
我找不到我在做什么错误。
//scheduling the alarm for repeating on selected days
public void scheduleDay(int request_code_value, String alarm_title)
{
Calendar calendar = Calendar.getInstance();
for(int i = 1; days.size() >= i; i++)
{
if ((days.get("" + i)) == 1)
{
// for creating different alarms adding i to request_code_value for uniqueness
request_code_value = request_code_value +i;
String filter_action = "com.ibkr.yowakeup" + request_code_value +"_time";
IntentFilter filter = new IntentFilter(filter_action);
registerReceiver(new AlarmReciever(), filter);
Intent intent = new Intent(filter_action);
intent.putExtra(getString(R.string.get_current_intent_value), request_code_value);
intent.putExtra(getString(R.string.alarmtext), alarm_title);
intent.putExtra(getString(R.string.alarm_time), newAlarm_Choose_Alarm_Value.getText().toString());
Log.d(TAG,"Scheduled on " + i + " = " + days.get("" + i));
calendar.set(Calendar.DAY_OF_WEEK, i);
calendar.set(Calendar.HOUR_OF_DAY, selected_hour);// cal.get(Calendar.HOUR_OF_DAY);
calendar.set(Calendar.MINUTE, selected_min);// cal.get(Calendar.MINUTE);
calendar.set(Calendar.SECOND, 0);// cal.get(Calendar.SECOND);
calendar.set(Calendar.MILLISECOND, 0);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, request_code_value , intent, 0);
alarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY * 7,
pendingIntent);
}
}
}
请帮我。提前致谢。