gpt4 book ai didi

Android 重复闹钟不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:51 25 4
gpt4 key购买 nike

这很好用:

Intent intent = new Intent(HelloAndroid2.this, AlarmReceiver.class);

PendingIntent pendingIntent = PendingIntent.getBroadcast(HelloAndroid2.this, 0,
intent, PendingIntent.FLAG_ONE_SHOT);

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (12 * 1000), pendingIntent);

这行不通。我只听到一次闹钟。

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (12 * 1000), 3 * 1000, pendingIntent);

我也试过这个,不走运:

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 5);

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 7000, pendingIntent);

问题是什么?

最佳答案

来自PendingIntent doc对于 FLAG_ONE_SHOT:

this PendingIntent can only be used once. If set, after send() is called on it, it will be automatically canceled for you and any future attempt to send through it will fail.

因此在 pendingIntent 第一次被触发后,它将被取消并且下一次尝试通过警报管理器发送它将会失败

尝试使用 FLAG_UPDATE_CURRENT

关于Android 重复闹钟不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4700058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com