警报应每月重复一次,每月一次,每月一次,每月一次,等等 就像我在10月31日发出警报一样,那么它应该在31个月的31个月内重复,因为我们每个月都没有相同的天数 我在找出此警报的间隔时遇到问题,请帮我弄清楚这个INTERVAL_Value必须是什么,或者如何以另一种方式处理它
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_Value, alarmIntent);
答案 0 :(得分:1)
我们可以从源接收当前的月值,它是一个整数
if (currentMonth == Calendar.JANUARY || currentMonth == Calendar.MARCH || currentMonth == Calendar.MAY || currentMonth == Calendar.JULY
|| currentMonth == Calendar.AUGUST || currentMonth == Calendar.OCTOBER || currentMonth == Calendar.DECEMBER){
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 31, alarmIntent);
}
if (currentMonth == Calendar.APRIL || currentMonth == Calendar.JUNE || currentMonth == Calendar.SEPTEMBER
|| currentMonth == Calendar.NOVEMBER){
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 30, alarmIntent);
}
if (currentMonth == Calendar.FEBRUARY){//for feburary month)
GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
if(cal.isLeapYear(year)){//for leap year feburary month
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 29, alarmIntent);
}
else{ //for non leap year feburary month
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 28, alarmIntent);
}
}
答案 1 :(得分:0)
您应该使用cal.getActualMaximum(Calendar.DAY_OF_MONTH));
。
这为您提供了每个月的最长日期,无论月份如何。