2

我正在开发一个 android 应用程序,用于每月设置警报。我已经给出了下个月的以下代码。

private int GetTotalDays(int  monthRecvd1) {

    int totalDays=getDaysInMonthInPresentYear(taskMonth1);
    myDays=(totalDays-taskdate1)+taskdate1;
            }

                private int getDaysInMonthInPresentYear(int taskMonth1) 
                {
                    int days=0;
                    alarmCalendar.set(Calendar.HOUR, Hrs);  
                    alarmCalendar.set(Calendar.MINUTE, Mins);
                    alarmCalendar.set(Calendar.SECOND, 0);
                    alarmCalendar.set(Calendar.DATE, date);
                    alarmCalendar.set(Calendar.MONTH, Month);
                    alarmCalendar.set(Calendar.YEAR, year);
                    Long alarmTime = alarmCalendar.getTimeInMillis();
                    calendar.set(year, Month, date);
                    days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

                 }   

此代码仅适用于下个月。并且在下个月的第二个不起作用。例如,如果我在四月设置闹钟,它将设置为五月而不是六月等。

谁能告诉我这可能是什么解决方案。

请帮忙!谢谢!

4

3 回答 3

0

使用setRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)方法而不仅仅是 AlarmManager.set()。您可以找到有关文档的更多信息。

http://developer.android.com/reference/android/app/AlarmManager.html

编辑:应该是这样的

public void onClick(View arg0) {
Intent serviceIntent = new Intent(AndroidAlarmService.this, this);
pendingIntent = PendingIntent.getService(AndroidAlarmService.this, 0, serviceIntent, 0);

AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 10);
long now = calendar.getTimeInMillis();
calendar.add(Calendar.DATE,calendar.getActualMaximum(Calendar.MONTH));
long repeat = calendar.getTimeInMillis();
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, now , repeat , pendingIntent);
}
于 2013-07-27T10:37:15.840 回答
0

尝试这个..

alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
        SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY,
        AlarmManager.INTERVAL_DAY, intent);
于 2013-07-27T11:29:53.583 回答
0

解决方案是显式强制文字为 long 类型,即 64 位数字:

am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTimefor30, 30L*1440L*60000L, pi);

资源:

每月设置警报android

于 2014-08-12T04:14:41.920 回答