내 앱에서 사용자가 설정 한 알람을 여러 번 원합니다. 그러나 다른 날짜와 시간으로 알람을 설정하면 마지막 설정 시간에만 응답합니다.Android에서 여러 번 알람 설정
이러한 내가 날짜 20-01-2017
시간 10.10 am
, 20-01-2017
시간 10.20 am
에 대한 알람, 그렇게 만 마지막에 선택한 날짜 & 시간에 대한 경보를 제공 10.30 am
, 및 20-01-2017
시간을 설정하는 경우 등. 20-01-2017
시간 10.10 am
, 20-01-2017
시간 10.20 am
또는 기타 선택한 시간에 경보를 보내지 않습니다.
선택한 모든 시간에 어떻게 알람을받을 수 있습니까?
public void setDate(View view) {
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getSupportFragmentManager(), "datePicker");
}
public void setTime(View view) {
DialogFragment newFragment = new TimePickerFragment();
newFragment.show(getSupportFragmentManager(), "timePicker");
}
public void setAlarm(View view) {
Calendar calNow = Calendar.getInstance();
Calendar calSet = (Calendar) calNow.clone();
calSet.set(Calendar.HOUR_OF_DAY, alarmHour);
calSet.set(Calendar.MINUTE, alarmMin);
calSet.set(Calendar.DAY_OF_MONTH, alarmDay);
calSet.set(Calendar.YEAR, alarmYear);
calSet.set(Calendar.MONTH, alarmMonth);
setAlarmN(calSet);
}
private void setAlarmN(Calendar targetCal) {
makeText(this, "Alarm is set at" + targetCal.getTime(),
LENGTH_LONG).show();
Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
getBaseContext(), RQS_1, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(),
pendingIntent);
}
//date picker fragment
public static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
alarmDay = day;
alarmYear = year;
alarmMonth = month;
}
}
//Time picker fragment
public static class TimePickerFragment extends DialogFragment
implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Do something with the time chosen by the user
alarmHour = hourOfDay;
alarmMin = minute;
}
}
다른 의도 ID를 사용하여 여러 번 실행해야합니다. 동일한 ID를 사용하면 이전 예약을 취소하고 새 예약을 설정합니다. –
나는이 문제에 대해 명확하지 않다. 어떻게 문제를 해결하기 위해 다른 의도 ID를 사용할 수 있습니까? – rabiul
'PendingIntent.getBroadcast'에는 4 개의 매개 변수가 있습니다. 두 번째 매개 변수는 요청 ID입니다. 'RQS_1'을 사용합니다. 모든 경보에 대해 다른 ID를 사용해보십시오. –