Android Fall detection

后端 未结 2 1387
孤城傲影
孤城傲影 2020-12-19 14:14

I am implementing the fall detection using accelerometer sensor, and create below code.

  public void onSensorChanged(SensorEvent foEvent) {


        if (f         


        
2条回答
  •  南笙
    南笙 (楼主)
    2020-12-19 14:52

    I got some solution not sure its work for all or not, but i am using below code and its working for me.

    if (foEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
    
            double loX = foEvent.values[0];
            double loY = foEvent.values[1];
            double loZ = foEvent.values[2];
    
            double loAccelerationReader = Math.sqrt(Math.pow(loX, 2)
                    + Math.pow(loY, 2)
                    + Math.pow(loZ, 2));
    
            DecimalFormat precision = new DecimalFormat("0.00");
            double ldAccRound = Double.parseDouble(precision.format(loAccelerationReader));
    
            if (ldAccRound > 0.3d && ldAccRound < 0.5d) {
               //Do your stuff
            }
       }
    

提交回复
热议问题