2012-05-02 51 views
0

報警我想創建一個在DatePicker的設置時間和TimePicker通知報警創建一個從的DatePicker和TimePicker

我的代碼是:

//Create alarm 
         GregorianCalendar tmpDate=new GregorianCalendar(datePicker.getYear(),datePicker.getMonth(),datePicker.getDayOfMonth()); 
         long date=tmpDate.getTimeInMillis(); 
         long hour=timePicker.getDrawingTime(); 
         long dateTime=date+hour; 
         calendar=new GregorianCalendar(); 

         if(dateTime<calendar.getTimeInMillis()){ 
          Toast.makeText(getApplicationContext(),"No puedes crear la alarma antes de hoy", Toast.LENGTH_SHORT); 
          return; 
         } 

AlarmManager alm=(AlarmManager)getSystemService(ALARM_SERVICE); 
     alm.set(AlarmManager.RTC_WAKEUP, dateTime,mAlarmSender);  

如果我試着加5秒的當前時間有效,但設置時間日期和時間選擇器不會通知。

回答

0

timePicker.getDrawingTime()不返回在timePicker中設置的時間。若要檢索您需要使用設定的時間一onTimeSetListener()(也this example見)

要檢查是否已經正確別人所做的一切,你可以登錄你有日期設置鬧鐘這樣前:

Log.d("test", "Current time is "+new Date().toLocaleString(); 
Log.d("test", "Date is "+new Date(dateTime).toLocaleString();