简体   繁体   English

电话不睡觉吗?

[英]Phone doesn't go to sleep?

Is it possible that if phone's screen turns off completely but phone does not go to sleep? 如果手机的屏幕完全关闭但手机没有进入睡眠状态,是否有可能?

I have an app which do some things when device goes to sleep. 我有一个应用程序,可以在设备进入睡眠状态时执行某些操作。 I registered broadcast intent: Intent.ACTION_SCREEN_OFF 我注册了广播意图:Intent.ACTION_SCREEN_OFF

On my device app works fine ( HTC Desire, cyanogenmod ). 在我的设备上,应用程序运行正常(HTC Desire,cyanogenmod)。 When screen turns off, my app is activated. 屏幕关闭时,我的应用程序已激活。

I tried app on another phone (HTC Wildfire S, offical gingerbread ), and here is the strange part. 我在另一部手机(HTC Wildfire S,官方姜饼)上尝试了该应用,这是奇怪的部分。 When screen goes off my app is not activated (sometimes it is, like 10%). 屏幕关闭时,我的应用未激活(有时是10%)。 So i connected it with my LOGCAT and i wanted to see if device actually goes to sleep when screen is turned off, and the thing is that when is connected with my PC, device ALWAYS goes to sleep and my app is activated. 因此,我将其与LOGCAT连接起来,我想查看关闭屏幕后设备是否真的进入睡眠状态,而事实是,当与PC连接时,设备始终会进入睡眠状态并激活我的应用程序。

On emulators from froyo to jelly bean app works perfect. 在从froyo到果冻豆的模拟器上,应用程序完美运行。 Is problem in my app? 我的应用程式出问题了吗?

From my testing of Screen Status broadcasts, I have learned that different manufacturers handle the screen off intents in different ways. 通过对屏幕状态广播的测试,我了解到不同的制造商以不同的方式处理屏幕关闭意图。 Can't really depend on the phone. 不能完全依靠电话。 You might want to use PowerManager to detect status of the device and take appropirate actions in onPause() 您可能想使用PowerManager来检测设备的状态并在onPause()中采取适当的措施

public static boolean isDeviceScreenOn(Context argContext) {
    PowerManager pm = (PowerManager) argContext.getSystemService(Context.POWER_SERVICE);
    return pm.isScreenOn();
}

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

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