拔下电源并进入睡眠状态时,我可以唤醒我的Android吗? [英] Can I wake up my Android when it is unplugged and sleeping?

查看:161
本文介绍了拔下电源并进入睡眠状态时,我可以唤醒我的Android吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个应用程序,可以收听广播并实现闹钟,以便在闹钟响起时可以播放收音机。我正在使用alarmManager和RTC_wakeup,并且如果插入电话或电话未入睡(似乎无法达到目的),它似乎可以正常工作。但是,当拔下电话并进入睡眠状态时,直到我唤醒电话后,警报才会响起。

I have made an app that allows one to listen to the radio and have implemented an alarm so that I can have the radio play when the alarm goes off. I am using the alarmManager and RTC_wakeup, and it seems to work fine if the phone is plugged in or if the phone is not asleep (which kind of defeats the purpose). When the phone is unplugged and asleep, however, the alarm does not go off until I wake up the phone.

有人知道对此有解决方案吗?

Does anyone know a solution to this?

推荐答案

我们就是这样做的,并且在您描述的两种情况下都有效:

This is how we did it and it works in both case that you describe:

PendingIntent pi = null;

private void startMonitor() {
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(this, OnTickReceiver.class);
    pi = PendingIntent.getBroadcast(this, 0, i, 0);

    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
            System.currentTimeMillis() + 120 * 1000, 120 * 1000, pi);
}

private void stopMonitor() {
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pi);
}

这篇关于拔下电源并进入睡眠状态时,我可以唤醒我的Android吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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