안녕하세요 맨땅에 헤딩하고 있는데..
캘린더 알람 기능을 구현 하려고 합니다.
단일 알림은 잘 되는데 특정 반복 할때 잘 되지 않아서...
일 주 월 년 반복알람을 하려고 합니다.;; 잘 되지 않아서..
public void SetLocalNotification(int notificationId,String RepetitionType,int Repetition_int ,String RepetitionWeeksdate, String message, String title , String bundle,int YEAR,int MONTH, int DATE,int HOUR_OF_DAY,int MINUTE)
{
// Log.i(TAG, "sendNotification notificationId:" + String.valueOf(notificationId) + " secAfter:" + String.valueOf(secAfter));
if (lastNotificatinId != -1) {
CancelLocalNotification(notificationId);
}
//Repetition_int 간격
//RepetitionWeeksdate 주 기간 일/월/화/수/목/금/토
AlarmManager am = (AlarmManager)currentActivity.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(currentActivity, LocalNotificationReceiver.class);
intent.putExtra("TITLE", title);
intent.putExtra("MESSAGE", message);
intent.putExtra("NOTIFICATION_ID", notificationId);
intent.putExtra("bundle", bundle);
Calendar calendar = Calendar.getInstance();
if((RepetitionType =="A") ||(RepetitionType =="")) //반복 없음
{
calendar.set(Calendar.YEAR, YEAR);
calendar.set(Calendar.MONTH, MONTH);
calendar.set(Calendar.DAY_OF_MONTH, DATE);
calendar.set(Calendar.HOUR_OF_DAY, HOUR_OF_DAY);
calendar.set(Calendar.MINUTE, MINUTE);
}
long user_set_time=1000 * 60 * 60 * 24 * 7;// 24시간
if(RepetitionType =="D") //일반복
{
calendar.set(Calendar.HOUR_OF_DAY, HOUR_OF_DAY);
calendar.set(Calendar.MINUTE, MINUTE);
user_set_time = user_set_time *Repetition_int; //24기준으로 간격날짜 곱했는데 맞는지..
}
if(RepetitionType =="W") //주반복
{
/*
if ( RepetitionWeeksdate == 1 ) m_week="일요일";
else if ( RepetitionWeeksdate == 2 ) m_week="월요일";
else if ( RepetitionWeeksdate == 3 ) m_week="화요일";
else if ( RepetitionWeeksdate == 4 ) m_week="수요일";
else if ( RepetitionWeeksdate == 5 ) m_week="목요일";
else if ( RepetitionWeeksdate == 6 ) m_week="금요일";
else if ( RepetitionWeeksdate == 7 ) m_week="토요일";
*/
//calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
calendar.set(Calendar.HOUR_OF_DAY, HOUR_OF_DAY);
calendar.set(Calendar.MINUTE, MINUTE);
user_set_time = user_set_time *(Repetition_int*7); //1주일이니 7일 곱했는데..
}
if(RepetitionType =="M")
{
calendar.set(Calendar.DAY_OF_MONTH, DATE);
calendar.set(Calendar.HOUR_OF_DAY, HOUR_OF_DAY);
calendar.set(Calendar.MINUTE, MINUTE);
user_set_time = user_set_time *(Repetition_int*7); //월을 모르겠습니다. 30일도 있고 31도 있어서..2월은 29일이라.
}
if((RepetitionType =="Y")||(RepetitionType =="L"))
{
calendar.set(Calendar.MONTH, MONTH);
calendar.set(Calendar.DAY_OF_MONTH, DATE);
calendar.set(Calendar.HOUR_OF_DAY, HOUR_OF_DAY);
calendar.set(Calendar.MINUTE, MINUTE);
user_set_time = user_set_time *(Repetition_int*365); //년
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if((RepetitionType =="A") ||(RepetitionType ==""))
{
am.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), PendingIntent.getBroadcast(currentActivity, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT));
}
else
{
am.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), user_set_time, PendingIntent.getBroadcast(currentActivity, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT));
}
}
else {
if((RepetitionType =="A") ||(RepetitionType ==""))
{
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), PendingIntent.getBroadcast(currentActivity, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT));
}
else {
am.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), user_set_time, PendingIntent.getBroadcast(currentActivity, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT));
}
}
lastNotificatinId = notificationId;
}
이 방법이 맞는지.. 아님 다른 방법이 있는지 알고 싶습니다.
부탁드립니다.