Detect Movement Accurately using Accelerometer in Android

后端 未结 3 2089
小蘑菇
小蘑菇 2021-02-03 13:10

I am implementing a demo TIMER, with Vibration ( at a particular condition ), When I press start my timer starts running.. and when I stop it using stop button, it simply stops.

3条回答
  •  庸人自扰
    2021-02-03 13:17

    I think the next stage in the development of your app is to look at values of acceleration that are produced in a spreadsheet. I use Excel for this, but any tool that can produce graphs will do. So alter onSensorChanged() to something like

    public void onSensorChanged(SensorEvent event) {
        float x = event.values[0];
        float y = event.values[1];
        float z = event.values[2];
    
        float mAccelCurrent = FloatMath.sqrt(x*x + y*y + z*z);
        float mAccel = mAccel * 0.9f + mAccelCurrent * 0.1f;
        Log.d("onSensorChanged",System.currentTimeMillis()+","+mAccelCurrent +","+mAccel);
    
    }
    

    and then you can capture the currentTime, mAccelCurrent and mAccel into the Android logging mechanism. Alternatively, create your own text file, write the values there, and open the file in a tool that can produce graphs. From the graphs, you can then decide what values to use for your trigger.

提交回复
热议问题