0

I'm having an issue with my AlarmManger:

The following correctly adds one day (because the time 9:25 has passed) the output is correct yet the AlarmManager calls the Broadcast within a couple seconds. Here's the relevant snippit. Any ideas?

Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 21);
    cal.set(Calendar.MINUTE, 25);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);


    Intent intent = new Intent(this, NotificationReceiver.class);
    NotificationReceiver instance = new NotificationReceiver();
    intent.setAction(instance.NOTIFICATION_SEND);
    intent.putExtra("TYPE",instance.NOTIFICATION_TYPE_PROGRESS);
    intent.putExtra("Ticker","Waiting for arrival.");
    intent.putExtra("ID",1);
    intent.putExtra("title","Check-In");
    intent.putExtra("message","A message");

    if(System.currentTimeMillis()>cal.getTimeInMillis()){
        if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY||cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY||cal.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY){
            cal.add(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
            Log.d("ALARMS","Set for monday.");
        }
        else{
            cal.add(Calendar.DATE,1);
            Log.d("ALARMS","Set for tomorrow. "+cal.get(Calendar.DAY_OF_MONTH));
        }
    }
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 24332, intent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),4000,pendingIntent);
4

1 回答 1

1

解决:

PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 24, intent, PendingIntent.FLAG_UPDATE_CURRENT);
于 2013-05-03T02:05:53.077 回答