2012-02-23 100 views
0

我如何才能設置報警管理的間隔,我用下面的代碼獲取時間毫秒從日曆對象:獲取毫秒從日曆一個月

am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), interval, sender); 

和我的計算interval用於獲取MilliSeconds的一個月如下:

Calendar monthCal = Calendar.getInstance(); 
monthCal.clear(); 
monthCal.setTimeInMillis(System.currentTimeMillis()); 
monthCal.add(Calendar.MONTH, 1); 

interval = monthCal.getTimeInMillis(); 

但我沒有得到任何重複的報警。

回答

1

你可以做到以下幾點:

Calendar c = Calendar.getInstance(); 
c.set(year,month,1); // Set the year and month you want milliseconds for 
long daysInMonth = c.getActualMaximum(Calendar.DATE); //Get how many days this month have 
long millisInMonth = daysInMonth*dayMillis; //Multiply the amount of days with how many milliseconds a day consists of (86400000L)