如何阻止警报管理器覆盖我的请求
How to stop alarm manager from overriding my request
警报管理器现在给我以下消息,可能是因为我开始使用 API 23.
03-21 13:00:03.828 754-2170/system_process W/AlarmManager: 可疑的短间隔 5000 毫秒;扩展到 60 秒
根据要求的规范,我需要 5000 毫秒的间隔。当我在我的 BroadCastReceiver 中告诉它 5000 毫秒时,你如何告诉它不要将它扩展到 60 秒?即
private static final long defaultPERIOD = 5000;
@Override
public void onReceive(Context ctxt, Intent i) {
context = ctxt;
scheduleAlarms(ctxt, (long) defaultPERIOD, true);
}
public static void scheduleAlarms(Context ctxt, Long duration, Boolean bactive) {
Log.e("FiveSecondReceivr", "scheduleAlarms duraton: "+duration);
AlarmManager mgr = (AlarmManager) ctxt
.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(ctxt, FiveSecondSchedule.class);
PendingIntent pi = PendingIntent.getService(ctxt, 0, i, 0);
mgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + duration, duration, pi);
if (bactive == false) {
mgr.cancel(pi);
}
}
Alarm manager is now giving me the following message, probably since I started using API 23.
没有,that has been the behavior since API Level 21 (Android 5.1)。
How do you tell it not to expand it to 60 seconds when I'm telling it 5000 millis in my BroadCastReceiver?
不要使用 "repeating" 系列方法。使用 setExact()
获得控制权,您可以在哪里工作,然后再次调用 setExact()
。这允许您减少到 5000 毫秒(虽然不会更低,并且该规则可能会在 Android 的未来版本中更改)。
警报管理器现在给我以下消息,可能是因为我开始使用 API 23.
03-21 13:00:03.828 754-2170/system_process W/AlarmManager: 可疑的短间隔 5000 毫秒;扩展到 60 秒
根据要求的规范,我需要 5000 毫秒的间隔。当我在我的 BroadCastReceiver 中告诉它 5000 毫秒时,你如何告诉它不要将它扩展到 60 秒?即
private static final long defaultPERIOD = 5000;
@Override
public void onReceive(Context ctxt, Intent i) {
context = ctxt;
scheduleAlarms(ctxt, (long) defaultPERIOD, true);
}
public static void scheduleAlarms(Context ctxt, Long duration, Boolean bactive) {
Log.e("FiveSecondReceivr", "scheduleAlarms duraton: "+duration);
AlarmManager mgr = (AlarmManager) ctxt
.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(ctxt, FiveSecondSchedule.class);
PendingIntent pi = PendingIntent.getService(ctxt, 0, i, 0);
mgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + duration, duration, pi);
if (bactive == false) {
mgr.cancel(pi);
}
}
Alarm manager is now giving me the following message, probably since I started using API 23.
没有,that has been the behavior since API Level 21 (Android 5.1)。
How do you tell it not to expand it to 60 seconds when I'm telling it 5000 millis in my BroadCastReceiver?
不要使用 "repeating" 系列方法。使用 setExact()
获得控制权,您可以在哪里工作,然后再次调用 setExact()
。这允许您减少到 5000 毫秒(虽然不会更低,并且该规则可能会在 Android 的未来版本中更改)。