检测音量按钮preSS时,屏幕关闭 [英] Detect Volume Button Press when Screen off

查看:177
本文介绍了检测音量按钮preSS时,屏幕关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的时候,我的Andr​​oid手机显示器开启或关闭detectes的服务。当关闭时,服务调用使用dispatchKeyEvent检测时,音量增大按钮已经pssed $ P $的活动。不幸的是,很明显的活动不能做到这一点,当屏幕处于关闭状态。 (见这个职位。)

I have a service that detectes when the display of my Android phone is turned on or off. When turned off, the service calls an activity that uses dispatchKeyEvent to detect when the volume up button has been pressed. Unfortunately, apparently the activity can't do this when the screen is off. (See this post.)

我注意到,虽然,事情在一定程度上被检测到时,因为出现以下LogCat中的消息时,我preSS当屏幕关闭音量向上键:CatService:返回当前sInstance 。该消息似乎是特定的设备,因为在不同的设备不同的东西出现在日志中,但我真的只关心第一个设备。

I've noticed, though, that something at some level is detecting that event, since the following LogCat message appears when I press the volume-up button when the screen is off: "CatService: Return current sInstance". The message seems to be device specific, since on a different device something different appears in the log, but I'm really only concerned about the first device.

我已经做了一些研究,CatService,但还没有找到太多,想不通我怎么可能能够使用它,或任何正在生成日志消息,来检测音量按钮preSS。我倒是AP preciate任何光线,任何人都可以在这个棚。

I've done some research into CatService, but haven't found much and can't figure out how I might be able to use it, or whatever is generating the log message, to detect the volume up button press. I'd appreciate any light that anyone can shed on this.

推荐答案

要保持检测这样的事情,当屏幕处于关闭状态的唯一方法是获得一个WakeLock,使屏幕关掉了,还是让你的应用程序功能。然而,这水渠电池寿命相当多,应该只使用在绝对必要的。

The only way to keep detecting things like this when the screen is off is to acquire a WakeLock that will allow the screen to turn off, and still let your app function. However, this drains the battery life quite a bit, and should only be used when absolutely necessary.

在这种情况下,您将需要一个 PARTIAL_WAKE_LOCK

In this case, you will need a PARTIAL_WAKE_LOCK.

这篇关于检测音量按钮preSS时,屏幕关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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