有人可以帮我修改这段代码,这样这个函数就可以在每个月的最后一天发出警报 . 目前能够获得当前月份,但应用程序没有在月末发出警报 . 谢谢

@Nikem,请这是我的请求,如果可能的话,我可以更多地了解我如何检查闹钟时间是否已经过去,以及如何通过示例代码设置下一个闹钟,因为我刚刚在android中编码 . 我的代码在这里:

Intent alarmIntent = new Intent(MainActivity.this,AlarmReceiver.class); pendingIntent = PendingIntent.getBroadcast(MainActivity.this,0,alarmIntent,PendingIntent.FLAG_UPDATE_CURRENT);

AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

//取消报警manager.cancel(pendingIntent);

/* Set the alarm to start at 12:30 AM at the last day of every month */
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());

    int currentMonth = calendar.get(Calendar.MONTH);

    if (currentMonth == Calendar.JANUARY || currentMonth == Calendar.MARCH || currentMonth == Calendar.MAY || currentMonth == Calendar.JULY
            || currentMonth == Calendar.AUGUST || currentMonth == Calendar.OCTOBER || currentMonth == Calendar.DECEMBER) {

        calendar.set(Calendar.HOUR_OF_DAY, 12);
        calendar.set(Calendar.MINUTE, 30);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.MONTH, currentMonth);
        calendar.set(Calendar.DAY_OF_MONTH, 31);
        manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), //+1000*60,
                1000 * 60 * 5, pendingIntent);
    }

    if (currentMonth == Calendar.APRIL || currentMonth == Calendar.JUNE || currentMonth == Calendar.SEPTEMBER
            || currentMonth == Calendar.NOVEMBER) {

        calendar.set(Calendar.HOUR_OF_DAY, 12);
        calendar.set(Calendar.MINUTE, 30);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.MONTH, currentMonth);
        calendar.set(Calendar.DAY_OF_MONTH, 30);
        manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), //+ 1000*60,//changed from setrepeating to setInexactRepeating
                1000 * 60 * 5, pendingIntent);
    }

    if (currentMonth == Calendar.FEBRUARY) {//for feburary month)
        GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
        if (cal.isLeapYear(2016)) {//for leap year feburary month
            calendar.set(Calendar.HOUR_OF_DAY, 12);
            calendar.set(Calendar.MINUTE, 30);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            calendar.set(Calendar.MONTH, currentMonth);
            calendar.set(Calendar.DAY_OF_MONTH, 29);
            manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), //+1000*60  changed from setrepeating to setInexactRepeating
                    1000 * 60 * 5, pendingIntent);
        } else { //for non leap year feburary month

            calendar.set(Calendar.HOUR_OF_DAY, 12);
            calendar.set(Calendar.MINUTE, 30);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            calendar.set(Calendar.MONTH, currentMonth);
            calendar.set(Calendar.DAY_OF_MONTH, 28);
            manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), //+1000*60, //changed from setrepeating to setInexactRepeating
                    1000 * 60 * 5, pendingIntent);
        }
    }

感谢您的回应和慷慨的支持 .