2013-05-03 53 views
0

我有我的AlarmManger一個問題:AlarmManager打算關閉前的時間

下正確添加一天(因爲時間9:25已過)的輸出是否正確尚AlarmManager調用內部的廣播幾秒鐘。這裏是相關的snippit。有任何想法嗎?

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); 

回答

1

解決:

PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 24, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
相關問題