将 triggerAtMillis 设置为 System.currentTimeMillis() 时,setRepeating 不会触发警报

No alarm fired with setRepeating when setting triggerAtMillis to System.currentTimeMillis()

我试图每 5 分钟发出一次警报,但我的经理在将 triggerAtMillis 参数设置为我当前的系统时间时没有发出任何警报。知道我该如何解决这个问题吗?

  manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  Intent alarmIntent = new Intent(this, AlarmReceiver.class);
 pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  int alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP;
  long intervalTime = 5*60*1000;
  manager.setRepeating(alarmType, System.currentTimeMillis(),intervalTime,pendingIntent);

这是我启动闹钟时的代码。因此,当我将 triggerAtmillis 设置为 triggerTime 时,它​​确实会触发,但不是每 5 分钟触发一次。

public class AlarmReceiver extends BroadcastReceiver {
Context context = null;
@Override
public void onReceive(Context arg0, Intent arg1) {
    context = arg0;
    System.out.println("test");
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("test")
                    .setContentText("test");
    Intent resultIntent = new Intent(context, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    mBuilder.setContentIntent(resultPendingIntent);
    mBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
    NotificationManager mNotificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(1, mBuilder.build());
}

我的接收器class

更改闹钟类型

int alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP;

int alarmType = AlarmManager.RTC_WAKEUP;

根据 api 文档,ELAPSED_REALTIME_WAKEUP 表示

time since boot, including sleep

RTC_WAKEUP 表示

wall clock time in UTC