简体   繁体   English

具有RTC_WAKEUP的AlarmManager不会唤醒设备

[英]AlarmManager with RTC_WAKEUP doesnt wake device

In my project, I have a service that connects to an HTTP to see if it's online. 在我的项目中,我有一个连接到HTTP的服务以查看它是否在线。 Everything works great, It does connect. 一切都很好,它确实可以连接。

The problem is when my device goes to sleep. 问题是我的设备何时进入睡眠状态。

I use the AlarmManager to trigger the check events, using RTC_WAKEUP, so that the process is run even when the screen is off... 我使用RTC_WAKEUP使用AlarmManager触发检查事件,因此即使屏幕关闭也可以运行该过程...

The problem is that this is not really happening. 问题在于这实际上并没有发生。 I created a Logging Method to see what happens behind the curtains of my app. 我创建了一个日志记录方法,以查看应用程序幕后发生的情况。

I log every step, writing the time it happened to see when and how things are happening. 我记录了每一步,记录了发生的时间,以查看发生的时间和方式。

When i set my device to sleep, and come back after a few minutes, I can see that the Alarm is triggering ONLY when I wake the device up, and not while it's sleeping. 当我将设备设置为睡眠状态并在几分钟后返回时,我可以看到仅在唤醒设备时才触发警报,而不是在睡眠时触发。

Here is the code in which I create the alarm: 这是我创建警报的代码:

public static void AddAlarm(Context pContext, Server pServer)
{
    // Create pending with intent and server object with a helper that creates  my pending intent.
    PendingIntent pending = IntentGenerator.GetPendingIntentForAlarm(pContext,pServer.ServerId);

    // Get alarm manager
    AlarmManager alarm = (AlarmManager)pContext.getSystemService("alarm");

    // Get current time to start now.
    long startNow = new Date().getTime()-10;

    // Set repeating alarm with current time to start, and interval.
    alarm.setRepeating(AlarmManager.RTC_WAKEUP ,startNow, pServer.GetIntervalInMilliseconds(), pending);
}

And in case you are wondering how i create the pending intent: 如果您想知道我如何创建待处理的意图,请执行以下操作:

public static Intent GetIntentForService(Context pContext, int pServerId)
{
    // Comienzo la alarma.
    Intent retVal = new Intent(pContext, ServerStatusCheckService.class);
    retVal.putExtra("SERVER_ID", pServerId);

    return retVal; 
}

I figured the problem was my own device. 我发现问题出在我自己的设备上。 It's a Zenithink C93 tablet. 这是Zenithink C93平板电脑。 I tested the same code on a Motorola Defy and it worked perfectly. 我在Motorola Defy上测试了相同的代码,并且运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM