我正在开发一个 android 应用程序,我在其中设置多个警报。警报可以设置一次,每天和每周。我将闹钟小时、分钟和上午/下午设置为
Calendar alarmCalendar = Calendar.getInstance();
alarmCalendar.set(Calendar.HOUR, 10);
alarmCalendar.set(Calendar.MINUTE, 45);
alarmCalendar.set(Calendar.SECOND, 0);
alarmCalendar.set(Calendar.AM_PM, 0);
Long alarmTime = alarmCalendar.getTimeInMillis();
如果时间经过,则以毫秒为单位进行比较
if(alarmType.equalsIgnoreCase("daily"))
{
if (currenttime >= alarmTime)
{
alarmTime+=86400000; // 1day in milliseconds
}
Intent intent = new Intent(Alarm.this, Reciever.class);
intent.putExtra("keyValue", key);
PendingIntent pi = PendingIntent.getBroadcast(Alarm.this, key, intent, PendingIntent.FLAG_UPDATE_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime, AlarmManager.INTERVAL_DAY, pi);
}
else if(alarmType.equalsIgnoreCase("weekly"))
{
if (currenttime >= alarmTime)
{
alarmTime+=604800000;//1 week in milliseconds
}
Intent intent = new Intent(Alarm.this, Reciever.class);
intent.putExtra("keyValue", key);
PendingIntent pi = PendingIntent.getBroadcast(Alarm.this, key, intent, PendingIntent.FLAG_UPDATE_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime, 604800000 , pi);
}
它在某些手机上工作正常,当闹钟时间过去时,每天和每周分别正确设置为第二天和下周。但是,问题是,在少数手机和平板电脑上,闹钟没有触发。任何人都可以说是什么问题。请帮助!谢谢!