我正在开发一个Android应用程序,我在其中设置多个alarm.Alarm可以设置为一次,每天和每周。 我将闹钟hrs,mins和am / pm设置为
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);
}
它在某些手机上正常工作,并且在闹钟时间结束后,每天和每周分别适当地设置为每天和每周。但问题是,在少数手机和平板电脑上,警报不会被触发。 任何人都可以说这个问题。请帮忙! 谢谢!