android repeating alarm, should repeat on monthly basis and on same day for each month so on after its set

前端 未结 2 784
忘了有多久
忘了有多久 2021-01-23 04:05

alarm should repeat on monthly basis, once a month on same date for each month so on after its set like if i place alarm on october 31, then it should repeat on 31 of months hav

2条回答
  •  走了就别回头了
    2021-01-23 04:54

    we can recieve currentMonth value from source and it is an integer

    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);
                }
        }
    

提交回复
热议问题