Android的TYPE_STEP_DETECTOR而屏幕关闭 [英] Android TYPE_STEP_DETECTOR while screen off

查看:558
本文介绍了Android的TYPE_STEP_DETECTOR而屏幕关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我开发一个使用TYPE_STEP_DETECTOR传感器类型为Android奇巧计步器程序,所有似乎直到我把屏幕关闭或锁定我的电话,我发现,它并不会触发一个事件,做工精细,当屏幕是关闭的。

Hello I'm developing a pedometer application that uses the TYPE_STEP_DETECTOR sensor type for Android KitKat, All seems to work fine until I turn the screen off or lock my phone, I find that it doesn't fire an event when the screen is off.

我知道TYPE_STEP_COUNTER变异的,但我不是太热衷于保持标签上起始计在每天每天的开始。我宁愿有触发的事件当检测到一个步骤,然后加1到当天的步数。

I am aware of the TYPE_STEP_COUNTER variant but I'm not too keen on keeping tabs on the starting count at the start of the day everyday. I would much rather have the event fired when a step is detected and then add "1" to the day's step count.

有没有人成功地使用了TYPE_STEP_DETECTOR在后台运行的服务,即使当屏幕关闭?

Has anyone successfully used the TYPE_STEP_DETECTOR in a service running in the background even when the screen is turned off?

code在sensorEventListener是:

code in sensorEventListener is:

if (source.equals(countSensor)) { // data came from step detector 
    // stepcount from step counter event.values[0]; 
    curStepCount = (int) event.values[0]; 
    stepcount += curStepCount;

打开屏幕的背面上我最终只有1步加计数后。

after turning the screen back on I end up with only 1 step added to the count.

推荐答案

现在的问题是功耗。如果手机的一个步骤发生,每次醒来的应用处理器,这将吸引更多的权力,并可能导致电池寿命差。使用手机时,制造商已经做出了决定,不支持唤醒版本的传感器,将打开手机时,被检测的一个步骤上。

The problem is power consumption. If the phone wakes up the application processor every time a step occurred, it will draw more power and could lead to poor battery life. With your phone, the manufacturer has made a decision NOT to support a "wake-up" version of the sensor that would turn the phone on when a step is detected.

为了节省电能,计数最好是在某种,通常是的ARM Cortex M4处理器,使用非常小的力量的运动协处理器完成。将其在<一个引入href="http://appleinsider.com/articles/13/10/31/google-unveils-new-nexus-5-with-m7-like-motion-tracker-android-44-kitkat"相对=nofollow>的Nexus 5 。如果您访问 TYPE_STEP_COUNTER 传感器,这会提供你所需要的

To conserve power, the counting is best done in a motion co-processor of some kind, typically a ARM Cortex M4 processor that uses very little power. This was introduced in the Nexus 5. If you access the TYPE_STEP_COUNTER sensor, this should provide what you need.

最后,Android的规范允许某人建立唤醒传感器,即东西,变成了应用处理器上,以显示你的应用程序,让你算吧。在这种特殊情况下,你不应该这样做,因为对电池寿命的影响很大这一点。

Lastly, the Android spec allows someone to establish a "wake-up" sensor, i.e. something that turns on the application processor to signal your app and allow you to count it. In this particular case, you shouldn't do this because of the large impact on battery life.

这行449起看到这里,请注意,它允许唤醒与非唤醒的版本: http://source.android.com/devices/halref/sensors_8h_source.html

See here from line 449 onwards, note that it allows "wake-up and non wake-up" version: http://source.android.com/devices/halref/sensors_8h_source.html

/*
 * SENSOR_TYPE_STEP_DETECTOR
 * reporting-mode: special
 *
 * A sensor of this type triggers an event each time a step is taken
 * by the user. The only allowed value to return is 1.0 and an event
 * is generated for each step.
 *
 * Both wake-up and non wake-up versions are useful.
 */

#define SENSOR_TYPE_STEP_DETECTOR                   (18)
#define SENSOR_STRING_TYPE_STEP_DETECTOR            "android.sensor.step_detector"

这篇关于Android的TYPE_STEP_DETECTOR而屏幕关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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