2

我想在每个月的 8 号设置一个通知。

这就是我所做的:

Intent myIntent = new Intent(remember.this, receiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(remember.this, 0, myIntent, 0);

        AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);


        // Set the alarm to start at approximately 8th of 
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.set(Calendar.DAY_OF_MONTH, 8);


        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                AlarmManager.INTERVAL_DAY*30, pendingIntent);

然而,我得到的是几分钟内不断的通知。这不会消失。

非常感谢您的帮助,因为我真的不知道哪里出了问题。

4

1 回答 1

-1

将日历设置为即将到来的本月 8 日。

alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis() , pendingIntent);

在receiver.class里面

public void onReceive(Context context, Intent intent) {
//do action needed
//invoke alarmManager in mainActivity
// cancel the previous alarm 
// set the new alarm for the next month
}
于 2015-04-29T12:55:23.863 回答