我能唤醒我的Andr​​oid时,它不是在和睡眠插入? [英] can i wake up my android when it is not plugged in and sleeping?

查看:108
本文介绍了我能唤醒我的Andr​​oid时,它不是在和睡眠插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个应用程序,允许一个听收音机。并实施报警,以便当警报响起时,我可以有广播剧。我使用的alarmManager和RTC_wakeup,它似乎正常工作,如果手机或堵塞,如果手机是不是睡着了(这种失败的目的),当手机被拔掉&放大器;睡着了报警,直到我醒来犯规熄灭电话,没有人知道解决这个?任何帮助是AP preciated,谢谢。

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&asleep the alarm doesnt go off until i wake up the phone, does anyone know a solution to this? any help is appreciated, thanks.

推荐答案

这是我们如何做到了,它在你描述的情况下都工作:

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

这篇关于我能唤醒我的Andr​​oid时,它不是在和睡眠插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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