【问题标题】:AlarmManager with RTC_WAKEUP doesnt wake device带有 RTC_WAKEUP 的 AlarmManager 不会唤醒设备
【发布时间】:2013-03-28 19:35:08
【问题描述】:

在我的项目中,我有一个连接到 HTTP 以查看它是否在线的服务。 一切都很好,它确实可以连接。

问题是我的设备何时进入睡眠状态。

我使用AlarmManager触发检查事件,使用RTC_WAKEUP,这样即使屏幕关闭,进程也能运行...

问题是这并没有真正发生。 我创建了一个日志记录方法来查看我的应用程序幕后发生的事情。

我记录每一步,记录它发生的时间,以了解事情发生的时间和方式。

当我将设备设置为睡眠并在几分钟后返回时,我可以看到警报仅在我唤醒设备时触发,而不是在它处于睡眠状态时触发。

这是我创建警报的代码:

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);
}

如果您想知道我如何创建待处理的意图:

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; 
}

【问题讨论】:

    标签: android android-service android-alarms


    【解决方案1】:

    我认为问题出在我自己的设备上。 这是 Zenithink C93 平板电脑。 我在 Motorola Defy 上测试了相同的代码,它运行良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多