2013-01-07 89 views
-1
@Override 
public void onTimeSet(TimePicker view, int hourOfDay, int minute) { 

    Calendar calNow = Calendar.getInstance(); 
    Calendar calSet = (Calendar) calNow.clone(); 

    calSet.set(Calendar.HOUR_OF_DAY, hourOfDay); 
    calSet.set(Calendar.MINUTE, minute); 
    calSet.set(Calendar.SECOND, 0); 
    calSet.set(Calendar.MILLISECOND, 0); 

    if(calSet.compareTo(calNow) <= 0){ 
     //Today Set time passed, count to tomorrow 
     calSet.add(Calendar.DATE, 1); 
    } 

    setAlarm(calSet); 
}}; 

private void setAlarm(Calendar targetCal){ 

    textAlarmPrompt.setText(
     "\n\n***\n" 
     + "Alarm is [email protected] " + targetCal.getTime() + "\n" 
     + "***\n"); 

    Intent intent = new Intent(getBaseContext(), AlarmReceiver.class); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1, intent, 0); 
    AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE); 
    // alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent); 
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(),AlarmManager.INTERVAL_DAY, pendingIntent); 
} 
+0

那麼你的問題是什麼? – Squonk

回答

0

您需要檢查此時間是否已經過去,否則警報將永遠不會被觸發。