我已将警报设置为在1天后重复。如何测试此代码是否真的会在1天后触发AlarmReceiver事件。 (显然,我不想等待1天来检查这是否真的有效)
我尝试在测试设备上更改时间。但它没有引发这一事件。
以下是代码:
public void showNotificationAtTime(final Context context, final long time, final int REQUEST_CODE, final boolean setRepeating, final long repeatAfter) {
Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, 0);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
if (setRepeating == true && repeatAfter >= 60000) {
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, repeatAfter, pendingIntent);
}
}