複数のアラームを設定しているAndroidアプリを開発しています。アラームは、毎日、毎週、1回に設定できます。アラームの時、分、午前/午後を次のように設定しています
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);
}
一部の電話では正常に機能し、アラーム時間が経過すると、毎日と毎週、それぞれ翌日と翌週に適切に設定されます。ただし、問題は、いくつかの電話とタブレットでは、アラームがトリガーされないことです。誰でも問題を教えてください。助けてください! ありがとう!