'setExact'和'setAlarmClock'之间的区别 [英] Difference between 'setExact' and 'setAlarmClock'

查看:189
本文介绍了'setExact'和'setAlarmClock'之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,它应该在指定时间触发警报,警报的目的是通过通知通知用户,我绝望地获得了一个非精确的结果。警报振铃,但不是在指定的时间。当警报设置和应该关闭的时间之间的时间很长时,这是系统的。
为此,我使用 setExact(RTC_WAKEUP,time,intent)。经过多次努力才能使它工作,我终于看到并尝试了 setAlarmClock 功能,一切都很顺利!!

In my application which was supposed to trigger an alarm at a specified time, alarm whose purpose was to inform the user via a Notification, I despaired at obtaining a non precise result. The alarm was ringing, but not at the specified time. This was systematic when the time between the setting of the alarm and the time it was supposed to go off was long. For this, I was using setExact(RTC_WAKEUP,time,intent). After many attemps to make it work, I finally saw and tried the setAlarmClock function, and everything went fine!!

根据javadoc, setAlarmClock setExact 相同,除非它暗示 RTC_WAKEUP 。据我所知,至少存在另外一个差异。有谁知道呢?

According to the javadoc, setAlarmClock is identical to setExact except that it implies RTC_WAKEUP. As far as I see, at least one other difference exists. Does anyone know it?

推荐答案

setExact() setAlarmClock() setImpl() 。如果您使用 RTC_WAKEUP 进行 setExact()调用,唯一的区别是<$ c $类型的最终arg c> AlarmClockInfo 。

setExact() and setAlarmClock() both make very similar calls to setImpl(). If you use RTC_WAKEUP for your setExact() call, the only difference is the final arg of type AlarmClockInfo.

在服务方面,通过 set()。在该方法结束时,我们可以看到额外参数产生的差异:

On the service side, the call is received in set(). At the end of that method, we can see the difference the extra argument makes:

@Override
public void set(int type, long triggerAtTime, long windowLength, long interval, int flags,
        PendingIntent operation, WorkSource workSource,
        AlarmManager.AlarmClockInfo alarmClock) {
    final int callingUid = Binder.getCallingUid();
    if (workSource != null) {
        getContext().enforcePermission(
                android.Manifest.permission.UPDATE_DEVICE_STATS,
                Binder.getCallingPid(), callingUid, "AlarmManager.set");
    }

    // No incoming callers can request either WAKE_FROM_IDLE or
    // ALLOW_WHILE_IDLE_UNRESTRICTED -- we will apply those later as appropriate.
    flags &= ~(AlarmManager.FLAG_WAKE_FROM_IDLE
            | AlarmManager.FLAG_ALLOW_WHILE_IDLE_UNRESTRICTED);

    // Only the system can use FLAG_IDLE_UNTIL -- this is used to tell the alarm
    // manager when to come out of idle mode, which is only for DeviceIdleController.
    if (callingUid != Process.SYSTEM_UID) {
        flags &= ~AlarmManager.FLAG_IDLE_UNTIL;
    }

    // If the caller is a core system component, and not calling to do work on behalf
    // of someone else, then always set ALLOW_WHILE_IDLE_UNRESTRICTED.  This means we
    // will allow these alarms to go off as normal even while idle, with no timing
    // restrictions.
    if (callingUid < Process.FIRST_APPLICATION_UID && workSource == null) {
        flags |= AlarmManager.FLAG_ALLOW_WHILE_IDLE_UNRESTRICTED;
    }

    // If this is an exact time alarm, then it can't be batched with other alarms.
    if (windowLength == AlarmManager.WINDOW_EXACT) {
        flags |= AlarmManager.FLAG_STANDALONE;
    }

    // If this alarm is for an alarm clock, then it must be standalone and we will
    // use it to wake early from idle if needed.
    if (alarmClock != null) {
        flags |= AlarmManager.FLAG_WAKE_FROM_IDLE | AlarmManager.FLAG_STANDALONE;
    }

    setImpl(type, triggerAtTime, windowLength, interval, operation,
            flags, workSource, alarmClock, callingUid);
}

如果有非空 alarmClock 参数,请求获取 FLAG_WAKE_FROM_IDLE 标记,位于 FLAG_STANDALONE 之上,您将获得该标记两种情况。以及对 <$ c的评论$ c> FLAG_WAKE_FROM_IDLE 说:

If there's a non-null alarmClock argument, the request gets the FLAG_WAKE_FROM_IDLE flag, on top of FLAG_STANDALONE, which you'll get in both cases. And the comment for FLAG_WAKE_FROM_IDLE says:


警报标志:此警报想唤醒设备,即使它是空闲的。例如,这是闹钟的闹钟。

Flag for alarms: this alarm would like to wake the device even if it is idle. This is, for example, an alarm for an alarm clock.

如果你愿意,你可以深入了解 FLAG_WAKE_FROM_IDLE 的使用情况 - 但据我所知,这就是区别。您的正常确切警报不会将设备从空闲状态唤醒,但使用setAlarmClock()设置的警报会停止。

If you want, you can dig into the usage of FLAG_WAKE_FROM_IDLE -- but that's the difference, as far as I can tell. Your "normal" exact alarms do not wake the device from idle, but the alarm set with setAlarmClock() does.

这篇关于'setExact'和'setAlarmClock'之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆