调度不适用于PM时间:Android

时间:2013-07-28 07:27:12

标签: android schedule

我已经申请了,而且工作得非常好。

我在调度方面遇到的一个问题。 我的应用程序中有自定义调度程序,我使用日期和时间选择器来选择日期/时间。如果是AM时间,那么这工作正常,但如果是PM时间那么它不起作用。我花了很多时间来解决它,但没有想到解决它。

选择日期的代码:

DatePickerDialog.OnDateSetListener dateEndSetListener = new DatePickerDialog.OnDateSetListener()
{   
    @Override
    public void onDateSet(DatePicker view, int year, int month, int date) 
    {
        mDay = date;
        mMonth = month;
        mYear = year;
    }
};
Calendar c = Calendar.getInstance();
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), dateEndSetListener, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
datePickerDialog.show();

选择时间的代码

TimePickerDialog.OnTimeSetListener timeEndSetListener = new TimePickerDialog.OnTimeSetListener()
{
    public void onTimeSet(TimePicker view, int hourOfDay, int minute)
    {
        mHour = hourOfDay;
        mMinut = minute;
    }
};
Calendar c = Calendar.getInstance();
TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(), timeEndSetListener, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), false);
timePickerDialog.show();

安排假电话的代码

AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmManagerForSchedullingCallBrodcastReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
Calendar time = Calendar.getInstance();
time.set(Calendar.DAY_OF_MONTH, date);
time.set(Calendar.MONTH, month);
time.set(Calendar.YEAR, year);
time.set(Calendar.HOUR, hour);
time.set(Calendar.MINUTE, minut);
time.set(Calendar.SECOND, 0);
am.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), pi);

非常感谢您的帮助..谢谢

1 个答案:

答案 0 :(得分:1)

我为自己的问题找到了解决方案。

我用 CODE BLOCK B 更改了 CODE BLOCK A ,如下所示:

代码阻止A

Calendar time = Calendar.getInstance();
time.set(Calendar.DAY_OF_MONTH, date);
time.set(Calendar.MONTH, month);
time.set(Calendar.YEAR, year);
time.set(Calendar.HOUR, hour);
time.set(Calendar.MINUTE, minut);
time.set(Calendar.SECOND, 0);
am.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), pi);

代码块B

Calendar time = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
time.set(year, month, date, hour, minut, 0);
am.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), pi);

它的神奇工作。我正在为那些面临同样问题的人发布这个答案。感谢