我正在使用 AlarmManager 来触发通知。我希望该通知在上午 10:30 触发,并每 24 小时重复一次。打开应用程序时我不想收到通知。
我正在发布我的代码,主要问题是它也会在晚上 10:30 发出警报(如果电话时区是 12 小时)。我检查了这段代码并进行了修改,并在晚上 10:30、1、4、7 收到警报。
请帮我解决这个问题,我一直在努力解决它。
代码 :
Intent myIntent = new Intent(Splash.this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(Splash.this,
0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar firingCal = Calendar.getInstance();
Calendar currentCal = Calendar.getInstance();
firingCal.set(Calendar.HOUR_OF_DAY, 10);
firingCal.set(Calendar.MINUTE, 30);
firingCal.set(Calendar.SECOND, 0);
long intendedTime = firingCal.getTimeInMillis();
long currentTime = currentCal.getTimeInMillis();
if (intendedTime >= currentTime) {
alarmManager.setRepeating(AlarmManager.RTC, intendedTime,
AlarmManager.INTERVAL_DAY, pendingIntent);
} else {
firingCal.add(Calendar.DAY_OF_MONTH, 1);
intendedTime = firingCal.getTimeInMillis();
alarmManager.setRepeating(AlarmManager.RTC, intendedTime,
AlarmManager.INTERVAL_DAY, pendingIntent);
}