传感器 StepCounter 有时在三星设备上无法正常工作 [英] Sensor StepCounter sometime not work well on SamSung device

查看:84
本文介绍了传感器 StepCounter 有时在三星设备上无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从这样的重启接收步骤创建一个演示.

I am create a demo from receive step from reboot like this.

public class MainActivity extends AppCompatActivity implements SensorEventListener {
    private SensorManager sensorManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        ...
        sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    }

    @Override
    protected void onResume() {
        super.onResume();
        countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);    
        sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
    }

    @Override
    public void onSensorChanged(SensorEvent event) {
        if (event.sensor.getType() == Sensor.TYPE_STEP_COUNTER) {
            Log.i("TAG","step from reboot" + String.valueOf(event.values[0]));
        }
    }
}

但是当我在我的设备(三星 Galaxy S4)上进行测试时,STEP_COUNTER 有时效果不佳:(.我通过与 SHealth

But when I test on my device (SamSung Galaxy S4), the STEP_COUNTER sometime not work well :(. I figure out it by compare with SHealth

经过多次测试我发现

几乎所有时间,STEP_COUNTER 返回步骤等于 健康 有时不同.因此我认为 SHealth 可以使用另一个传感器来计算步数,但我不知道是哪个传感器?我认为它不是 STEP_DETECTOR 因为 STEP_DETECTOR 关闭屏幕时返回很少的步骤.

Almost time, STEP_COUNTER return the step equals SHealth BUT sometime different. Therefore I think SHealth may use another sensor for counting step but I don't know which sensor? I think it is not STEP_DETECTOR because STEP_DETECTOR return very few step when turn off the screen.

有时,STEP_COUNTER 停止工作,而 SHealth 仍然返回步骤例如,我走了大约 100 步 => SHealth 显示 110 和演示应用程序显示 100,然后我继续走大约 200 步 => SHealth 显示 305 和演示应用程序显示 121(似乎它停止工作)

Sometime, STEP_COUNTER stop working while SHealth still return the step, for example, I walk about 100 steps => SHealth display 110 and demo app display 100, then I continue walk about 200 steps => SHealth display 305 and demo app display 121 (seem like it stop work)

我也收到了许多使用不同设备的用户的报告(评分较低 :( ),但我只能在我的设备上重现它.

I also receive the report from many user with different device (with low rating :( ) but I can only reproduce it on my device.

我不知道如何解决这个问题.我认为 STEP_COUNTER 是接收步骤的最佳传感器(比较使用 STEP_DETECTOR)

I don't know how to fix this problem. I think STEP_COUNTER is the best sensor for receive step (compare with STEP_DETECTOR)

任何帮助或建议将不胜感激.

Any help or suggestion would be great appreciated.

推荐答案

我们也遇到过这个问题,当使用手机的默认步数传感器时.但是,我们正在使用 TYPE_STEP_DETECTOR - 我们不没有您遇到的问题(超过 100000 个用户),所以可能有问题?这个问题与您不能依赖这种机制的方式非常相似.对于我们的案例,我们在很短的时间内收到了很多步骤.就算是老虎,也走不了那么多步.

We've also encountered in this problem, when using the default steps sensors of the phone. However, we're using TYPE_STEP_DETECTOR - and we don't have the issue you have(more than 100000 users), so perhaps something is wrong there? This issue is quite resemble in the way that you can't rely on such mechanism. For our case, we've received a lot of steps in a short amount of time. Even if you're a tiger, you can't make that many steps.

事情是这样的,三星操纵操作系统,并且有很多东西可以很好地运行在例如 nexus 设备上,但不适用于三星设备.在尝试修复步进传感器的行为后,我们发现我们需要为三星手机或不支持它的手机提供替代方案.

Here's the thing, Samsung manipulates the OS and there are a lot of stuff that works well on say, nexus devices, BUT not on Samsung devices. After trying to fix the behaviour of the step sensor, we've figured out we need an alternative for Samsung phones, or, for phones that do not support it.

仅供参考,我们遇到过某些手机(主要是摩托罗拉)在设备中没有步数传感器,因此尝试查找传感器时返回 null.

FYI, We've encountered that some phones (mostly Motorola) doesn't have the steps sensors in the device, so trying to find the sensors, returns null.

  SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
  Sensor stepDetector = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
  if (stepsDetector != null) {
     //Do something
  }

您可以使用唤醒锁和加速度计(电池消耗巨大,当心).

这篇关于传感器 StepCounter 有时在三星设备上无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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