我正在使用此代码,并且我的 AlarmManager 立即触发,因为触发时间还有触发时间我将其打印在 LOG 上,以便您查看。
public void SetAlarm(Context context, Date date, List<String> temp) {
Log.d("Alarm Set", "Entered");
Log.d("Alarm Set", date.getHours() + " " + date.getMinutes());
AlarmManager am = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, Alarm.class);
i.putStringArrayListExtra("list", (ArrayList<String>) temp);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i,
PendingIntent.FLAG_ONE_SHOT);
date.setMinutes(date.getMinutes() - 5);
Calendar rightNow = Calendar.getInstance();
long offset = rightNow.get(Calendar.ZONE_OFFSET)
+ rightNow.get(Calendar.DST_OFFSET);
long sinceMidnight = (rightNow.getTimeInMillis() + offset)
% (24 * 60 * 60 * 1000);
long time_in_milis = (1000 * 60 * ((date.getHours() * 60) + date
.getMinutes())) - sinceMidnight;
Log.d("Alarm Time in Mili Seconds", "" + time_in_milis);
am.set(AlarmManager.RTC_WAKEUP, time_in_milis * 10000, pi);
}