2016-03-02 192 views
0

我正在使用此代碼廣播特定日期的鬧鐘。但它每天都在響。誰可以幫我這個事?設置特定工作日的鬧鐘。但是每天鬧鐘響起

calendar.set(Calendar.HOUR_OF_DAY, hours); 
calendar.set(Calendar.MINUTE, minute); 
calendar.set(Calendar.SECOND, 0); 
calendar.set(Calendar.DAY_OF_WEEK, weekdayList.get(x)); 
Intent myIntent = new Intent(getApplicationContext(), AlarmReceiver.class); 
myIntent.putExtra("reminder_id",value+""); 
myIntent.putExtra("reminder_title", title.getText().toString()); 

pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), value1, myIntent, PendingIntent.FLAG_CANCEL_CURRENT); 


// alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent); 
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 
      calendar.getTimeInMillis(), 1000 * 60 * 60, pendingIntent); 
+1

請顯示所有變量的類型。更好的是,使其成爲[最小,完整和可驗證的示例。](http://stackoverflow.com/help/mcve)。 –

+0

我需要針對我的一個應用程序解決這樣的問題;一個答案會很有幫助 – Eenvincible

+0

我在這裏得到了一個解決方案。它爲我工作。我必須使用sqlite數據庫。 http://stackoverflow.com/questions/14272295/how-can-i-get-the-repeat-alarm-for-week-days-using-alarm-manager –

回答

0

如果您想安排它只有一次:

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

如果你想每週重複一遍:

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 
     calendar.getTimeInMillis(), alarmManager.INTERVAL_DAY * 7, pendingIntent); 

記住你設置日曆變量時採取謹慎。據DOCS:

對於集()

如果規定的觸發時間是在過去,報警器會立即觸發 。如果此意圖預定爲 (其中兩個意圖的相等性由 filterEquals(意圖)定義)已經有一個警報,那麼它將被刪除並替換爲此 之一。

對於setRepeating()

如果規定的觸發時間過去,報警器會立即根據觸發時間是怎麼過去遠觸發,與報警計數相對於重複間隔。

+0

在這裏得到了一個解決方案。謝謝任何方式:) http://stackoverflow.com/questions/14272295/how-can-i-get-the-repeat-alarm-for-week-days-using-alarm-manager –