Я делаю проект в android, и я хочу создать будильник в течение нескольких дней, но проблема в том, что когда я выбираю несколько дней, будильник будет отображаться только в последний день. Вот моя попыткаНесколько сигналов тревоги в android
public void onClick(View v) {
CheckBox box1=(CheckBox)findViewById(R.id.checkBox1);
CheckBox box2=(CheckBox)findViewById(R.id.checkBox2);
CheckBox box3=(CheckBox)findViewById(R.id.checkBox3);
CheckBox box4=(CheckBox)findViewById(R.id.checkBox4);
CheckBox box5=(CheckBox)findViewById(R.id.checkBox5);
CheckBox box6=(CheckBox)findViewById(R.id.checkBox6);
CheckBox box7=(CheckBox)findViewById(R.id.checkBox7);
/** Getting a reference to TimePicker object available in the MainActivity */
TimePicker tpTime = (TimePicker) findViewById(R.id.tp_time);
int hour = tpTime.getCurrentHour();
int minute = tpTime.getCurrentMinute();
Calendar c=Calendar.getInstance();
int month;
int day;
int year;
Date date =new Date();
c.setTime(date);
if(box1.isChecked()) {
/** This intent invokes the activity DemoActivity, which in turn opens the AlertDialog window */
Intent i = new Intent("com.example.servicealarmdemo2.demoactivity");
/** Creating a Pending Intent */
PendingIntent operation = PendingIntent.getActivity(getBaseContext(), 0, i, Intent.FLAG_ACTIVITY_NEW_TASK);
c.setTime(date);
c.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
month=c.get(Calendar.MONTH);
day=c.get(Calendar.DATE);
year=c.get(Calendar.YEAR);
/** Getting a reference to the System Service ALARM_SERVICE */
AlarmManager alarmManager1 = (AlarmManager) getBaseContext().getSystemService(ALARM_SERVICE);
/** Creating a calendar object corresponding to the date and time set by the user */
GregorianCalendar calendar = new GregorianCalendar(year,month,day, hour, minute);
/** Converting the date and time in to milliseconds elapsed since epoch */
long alarm_time = calendar.getTimeInMillis();
/** Setting an alarm, which invokes the operation at alart_time */
alarmManager1.set(AlarmManager.RTC_WAKEUP , alarm_time , operation);
alarmManager1.setRepeating(AlarmManager.RTC_WAKEUP,alarm_time,7*24*3600*1000, operation);
}
if(box2.isChecked()) {
Intent i = new Intent("com.example.servicealarmdemo2.demoactivity");
PendingIntent operation = PendingIntent.getActivity(getBaseContext(), 0, i, Intent.FLAG_ACTIVITY_NEW_TASK);
c.setTime(date);
c.set(Calendar.DAY_OF_WEEK,Calendar.TUESDAY);
month=c.get(Calendar.MONTH);
day=c.get(Calendar.DATE);
year=c.get(Calendar.YEAR);
AlarmManager alarmManager2 = (AlarmManager) getBaseContext().getSystemService(ALARM_SERVICE);
GregorianCalendar calendar = new GregorianCalendar(year,month,day, hour, minute);
long alarm_time = calendar.getTimeInMillis();
alarmManager2.set(AlarmManager.RTC_WAKEUP , alarm_time , operation);
alarmManager2.setRepeating(AlarmManager.RTC_WAKEUP,alarm_time,7*24*3600*1000, operation);
}
Любая помощь будет оценена
Возможно, мне что-то не хватает, но в чем разница между проверкой 'box1' и' box2'? –
Я думаю, что [это] (http://stackoverflow.com/questions/18545115/setting-multiple-alarms-on-my-alarm-application) может ответить на ваш вопрос. Использование того же 'PendingIntent' заменит будильник. Его также упоминается в [документации] (https://developer.android.com/reference/android/content/Intent.html#filterEquals%28android.content.Intent%29) –
флажки указаны для тех дней, когда мое приложение проверяет дни и создайте аварийные сигналы для выбранных дней – user3008437