[英]Set monthly repeating notification in Android
我想在每個月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);
但是我得到的是幾分鍾之內不斷的通知。 而且這不會消失。
非常感謝您的幫助,因為我真的不知道哪里出了問題。
將日歷設置為每月的8號。
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis() , pendingIntent);
內部receive.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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.