0

我对 Android 中的警报管理器有疑问。我有以下代码片段来设置每周(一次)应该触发的警报。

  // Add the time and set when the notification will be triggered
    Calendar setCalendar = item.getDate();
    calendar.set(Calendar.MINUTE,setCalendar.get(Calendar.MINUTE)+10080);

   //Create a new alarm intent
   Intent alarmIntent = new Intent(ApplicationUtils.getApplicationContext(), AlarmReceiver.class);


   PendingIntent sender = PendingIntent.getBroadcast(ApplicationUtils.getApplicationContext(), requestCode, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        // Get the AlarmManager service
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(context.ALARM_SERVICE);
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.ELAPSED_REALTIME, sender);

我必须关注问题。当一周改变时,通知就会出现并且它们永远不会停止。有人知道如何设置日历以便每周触发一次警报吗?

谢谢,阿克德

4

2 回答 2

1

你的第三个参数setRepeating不正确。它应该是重复警报之间的间隔(以毫秒为单位)。

一周将是: 1000 * 60 * 60 * 24 * 7 。

http://developer.android.com/reference/android/app/AlarmManager.html#setRepeating(int , long, long, android.app.PendingIntent)

于 2012-06-10T11:36:13.633 回答
1

查看对您有帮助的代码。

 Intent intent_for_every_second = new Intent(Activity.this, Notifier.class);
 pendingIntent_for_every_second = PendingIntent.getBroadcast(Activity.this, 0,    intent_for_every_second,0);
 AlarmManager alarmManager_for_every_second = (AlarmManager) getSystemService(ALARM_SERVICE);
  alarmManager_for_every_second.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 1000, 1000,pendingIntent_for_every_second);
于 2012-06-10T11:45:11.367 回答