簡體   English   中英

警報並非在每天的特定日期重復(例如,周日,周二,周五)

[英]alarm repeating at specific day not every day example ( Sunday, Tuesday , Friday)

我厭倦了尋找有關警報的特定日期,並且每天都在運行請誰來幫助我並使用這些代碼的錯誤嗎,請每天運行,以便我發送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); 
}

經過快速瀏覽后,我看到您將警報設置為每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);

最后,如果將此正確的解決方案設置為(sun,tus,fri),則必須為這三天創建三個警報,以下代碼在每個星期日設置警報並發送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);

} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM