安卓:如何收集传感器值的一段固定的时间? [英] Android: How to collect sensor values for a fixed period of time?

查看:201
本文介绍了安卓:如何收集传感器值的一段固定的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想收集约5秒加速度的值。什么是做一个适当的方式?

I want to collect for ca. 5 seconds the values of the Accelerometer. What is a proper way to do this?

我试了一下通过实现注册一个AsyncTask的和注销本身在传感器经理为加速度计,然后睡5秒。但睡在onSensorChanged方法的5S过程中不会被调用:D ...

I tried it by implementing an AsyncTask which registers and unregisters itself at the sensor manager for the accelerometer and then sleeps for 5 seconds. But during those 5s of sleeping the onSensorChanged method isn't invoked :D...

我的追求背后的动机是:
为了校准我的加速度我想收集一些秒传感器值(而手机趴在地板上),然后通过计算平均值得到偏差...

The motivation behind my sought is the following: In order to calibrate my accelerometer I want to collect for some seconds sensor values (while the phone is lying on the floor) and then get the bias by computing the mean values...

我AP preciate任何暗示!

I appreciate any hint!

推荐答案

假设你开始你传感器onResume:

Assuming you are starting your sensors in onResume:

/**
 * start sensors
 */
public void onResume() {
    mSensorManager.registerListener(mListener, mSensorAcceleration, SensorManager.SENSOR_DELAY_GAME);
    mSensorManager.registerListener(mListener, mSensorMagnetic, SensorManager.SENSOR_DELAY_GAME);
    Handler h = new Handler();
    h.postDelayed(new Runnable() {

        @Override
        public void run() {
        //    do stuff with sensor values
            mSensorManager.unregisterListener(mListener);               
        }
    }, 5000);
...

这篇关于安卓:如何收集传感器值的一段固定的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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