2014-09-10 36 views
2

我累了查找有關報警的具體日子,總是天天跑懇求誰可以幫我 並使用這些代碼,這個是什麼錯誤,運行每所以我發送dayOfWeek = 1;但每天跑報警在特定日子不是每天例如重複(週日,週二,週五)

public void setAlarm(int dayOfWeek) { 
    Toast.makeText(getApplicationContext(), dayOfWeek+","+h+","+m, 22222).show(); 
    cal1.set(Calendar.DAY_OF_WEEK, dayOfWeek); 
    cal1.set(Calendar.HOUR, 11); 
     cal1.set(Calendar.MINUTE, 0); 
     cal1.set(Calendar.SECOND, 0); 
     cal1.set(Calendar.MILLISECOND, 0); 
     Intent intent = new Intent(this, RemmemberActivity.class); 
     PendingIntent pendingIntent0 = PendingIntent.getBroadcast(this, 0, 
       intent, 0); 
     pendingIntent = PendingIntent.getActivity(this, 12345, 
       intent, PendingIntent.FLAG_UPDATE_CURRENT); 

      Long alarmTime = cal1.getTimeInMillis(); 
      am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE); 
     am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,24 * 60 * 60 * 1000 , pendingIntent); 
} 

回答

0

什麼我可以爲您設置報警每24小時重複該行快速瀏覽一下之後,會後:

am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,24 * 60 * 60 * 1000 , pendingIntent); 

dayOfWeek只用於當它熄滅第一次。

如果您有一個警報應該在同一時間每週關閉三次,請製作三個一週重複一次的警報。

am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime, 7 * 24 * 60 * 60 * 1000 , pendingIntent); 
+0

確定,但我沒有固定3天(太陽,週二,週五),可能是三個不同天根據複選框選擇像一個(週一,週三,週六) – 2014-09-14 06:51:32

+0

好吧,我用這條線和每週六罰款am.setRepeating(AlarmManager.RTC_WAKEUP,alarmTime,7 * 24 * 60 * 60 * 1000,pendingIntent);但怎麼可以設置每個星期天 – 2014-09-14 07:41:03

+0

謝謝你的幫助:) :) – 2014-09-14 08:32:49

0

最後,如果設置爲(太陽,土族,星期五),你必須創建 這三天下面的代碼設定的報警三個報警每個星期天和發送一個dayOfWeek = 1這個正確的解決方案; 重要注意每個創建的某一天運行必須在每個INTNET變更請求的代碼(12345) 例如

public void setAlarm_sun(int dayOfWeek) { 
    cal1.set(Calendar.DAY_OF_WEEK, dayOfWeek); 
    Toast.makeText(getApplicationContext(), "sun "+cal1.get(Calendar.DAY_OF_WEEK), 222).show(); 

    Toast.makeText(getApplicationContext(), "Finsh", 222).show(); 

     Intent intent = new Intent(this, SecActivity.class); 
     PendingIntent pendingIntent0 = PendingIntent.getBroadcast(this, 0, 
       intent, 0); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 12345, 
       intent, PendingIntent.FLAG_UPDATE_CURRENT); 

     Long alarmTime = cal1.getTimeInMillis(); 
     AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE); 

     // am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,7* 24 * 60 * 60 * 1000 , pendingIntent); 
     am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,7* 24 * 60 * 60 * 1000 , pendingIntent); 

} 
相關問題