0
我希望得到用戶的日期和時間與TimePickerDialog和DatePicker的,然後顯示在時間通知當用戶選擇的,但通知顯示在當前時間AlarmManager不正確的工作
獲取時間:
TimePickerDialog tpd=new TimePickerDialog(AddTaskActivity.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Model_Static.bol_time=true;
hourFinal=view.getCurrentHour();
MinuteFinal=view.getCurrentMinute();
tv4.setText(hourOfDay+":"+minute);
}
},hour,minute,true);
tpd.show();
獲得年月日:
btn_sbt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Model_Static.bol_tarikh=true;
Calendar cal=pdp.getDisplayPersianDate();
Toast.makeText(getApplicationContext(),cal.getTimeInMillis()+"",Toast.LENGTH_LONG).show();
yearFinal=cal.getTime().getYear();
monthFinal=cal.getTime().getMonth();
dayFinal=cal.getTime().getDay();
集AlarmManager:
if (Model_Static.bol_tarikh&&Model_Static.bol_time)
{
intent123.putExtra("id",2);
pendingIntent123=PendingIntent.getBroadcast(getApplicationContext(),2,intent123,PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calcal=Calendar.getInstance();
calcal.set(Calendar.YEAR,yearFinal);
calcal.set(Calendar.MONTH,monthFinal);
calcal.set(Calendar.DAY_OF_MONTH,dayFinal);
calcal.set(Calendar.HOUR_OF_DAY,hourFinal);
calcal.set(Calendar.MINUTE,MinuteFinal);
long b=calcal.getTimeInMillis();
am123.set(AlarmManager.RTC,b,pendingIntent123);
你真的應該首先嚐試調試代碼,發送問題做之前。設置一些斷點,單步執行代碼,看看你的變量是如何改變到達線'am123.set(AlarmManager.RTC,B,pendingIntent123)之前;' – artkoenig