android - 如何存储加速度计值

标签 android progress-bar accelerometer

我有这个代码:

public class Chronom extends Activity 
{

    Chronometer mChronometer;
    ProgressBar progre;

    int total=1;


    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        //layout
        setContentView(R.layout.main7watingscreen);

        //Start Chronometer
        mChronometer = (Chronometer) findViewById(R.id.chrono1);
        mChronometer.start();

        progre = (ProgressBar) findViewById(R.id.progressBar1);

        MyCount counter = new MyCount(31000,300);
        counter.start();
    }


    public class MyCount extends CountDownTimer
        {
            public MyCount(long millisInFuture, long countDownInterval) 
            {
                super(millisInFuture, countDownInterval);
            }
            @Override
            public void onFinish() 
            {
                Intent myIntent = new Intent( Chronom.this, MainMenu.class);
                startActivityForResult(myIntent, 0);
            }
            @Override
            public void onTick(long millisUntilFinished) 
            {
                total++;
                progre.setProgress(total);         
            }   

        }

我想将加速度计值(x、y 和 z)存储在一个矢量中(可以是其他形式,我想知道您的意见)。

但我想在进度条充满的同时执行此操作(它在 30 秒后停止)。比如在 1 秒开始存储并在 30 秒后停止。

如果你不明白我的问题,请说出来,我会更好地解释。

怎么做?请帮忙!

最佳答案

通过 onSensorChanged() 回调(参见 SensorListener 引用),您每次更改传感器值时都可以获取它们。 您无法在设定的时间查询传感器数据

有一种解决方法:让监听器在每次更改时保存值(即在 onSensorChanged() 方法中),并查询这些保存的值使用你的计时器。例如,您可以为其使用 static float[] 数组或 SharedPreferences 值。

关于android - 如何存储加速度计值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6391512/

相关文章:

java - android项目有红色x但代码没有错误

java - Android Studio - 创建模拟进度条

android - 使用加速度计(陀螺仪?)在 2D 空间中绘图

c# - WP7 中的加速度计问题

android - "System services not available to Activities before onCreate()"错误信息?

android - 在 Node 中发送 GCM 推送

android - 如何为 FirebaseMessagingService 实现 onDeletedMessages()?

使用 NSTimer 快速查看进度

java - 在 InputStream 之前获取 FileSize

iphone - iPhone 的加速度计有多精确——是否可以绘制出相对准确的手机位置运动路径?