由于AM/PM,在获取时间设置 AlarmManger 以使用 TimePicker 时发出调度警报

Issues scheduling alarms when getting the time to set the AlarmManger for using a TimePicker because of AM/PM

我正在编写一个应用程序,该应用程序具有一项功能,用户可以使用该功能为要发送给某人的 SMS 消息设置闹钟。我遇到的问题是用户将警报管理器设置为在 9:00 A.M 时关闭。目前是 10:00 P.M。然后警报立即响起。它不承认应该为第二天设置闹钟的事实。

这里是设置 AlarmManager 的代码:

Intent intentAlarm = new Intent(MainMenu.this, AlarmReceiver.class);
intentAlarm.putExtra("phoneNumber", phoneNumber);
intentAlarm.putExtra("message", message);
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), PendingIntent.getBroadcast(MainMenu.this, 1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));


除了 AM/PM 问题,AlarmManager 运行良好。我只是不知道从这里去哪里,我正在查看的所有文档都没有帮助。

public void SetAlarm(Context context) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
    // set alarm after 12 hours
    long after = System.currentTimeMillis() + 12 * 60 * 60 * 1000;
    am.set(AlarmManager.RTC_WAKEUP, after, pi);
}
Calendar cal1 = Calendar.getInstance();
    cal1.set(Calendar.HOUR_OF_DAY, 10); // use hour of day for am pm issue
    cal1.set(Calendar.MINUTE, 00);
    cal1.set(Calendar.SECOND, 00);

    Calendar now = Calendar.getInstance();
        if (now.after(cal1))
            cal1.add(Calendar.DAY_OF_YEAR, 1);
// this code snippet add one day if the current time passed away 
//else use cal1.set(year, month, day); for exact day