0

I am trying to make an app for simple fall detect. I am trying something like below-

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //.....................

    //Creating Sensor Manager
    SM = (SensorManager) getSystemService(SENSOR_SERVICE);

    //Accelerometer Sensor
    sensor = SM.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}


@Override
public  void onSensorChanged(final SensorEvent event){
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){
        sum = Math.round(Math.sqrt(Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2) + Math.pow(event.values[2], 2)));

        //binding with a possible range
        if (sum <= 20.0){
            min = true;
        }

        if (min == true){
            if (sum >= 40.0){
                max = true;
            }
        }

        if (min == true && max == true){
            SM.unregisterListener(this);
            Toast.makeText(this,"Fall", Toast.LENGTH_SHORT).show();
            //doing other stuff like - countdown timer with alert dialog, sending sms etc.
        }
    }
}

I am facing some problem with it. It's not giving the result when falling a person with the mobile in his pocket and giving sometimes false result when walking(faster). To improve this what should I do, Would someone help me please?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
sKhanm
  • 37
  • 3
  • Does this answer your question? [Android Fall detection](https://stackoverflow.com/questions/44518729/android-fall-detection) – Froyo Dec 06 '19 at 13:40
  • You need tweak your thresholds probably. – Froyo Dec 06 '19 at 13:40
  • @Froyo I tried this. But, it does not work for me. – sKhanm Dec 06 '19 at 14:11
  • Would you please tell me more about `tweak thresholds` – sKhanm Dec 06 '19 at 14:13
  • When you are writing `sum >= 40.0` - How did you come up with this number? Do you think a smaller or higher number would be helpful? Maybe, you could add more weight to `z index` compared to `y index`. There are a lot of factors. There's no straight answer. – Froyo Dec 06 '19 at 15:46
  • @Froyo thanks for your reply. Should I use vector mathematics like this accepted answer? https://stackoverflow.com/questions/4848490/android-how-to-approach-fall-detection-algorithm – sKhanm Dec 06 '19 at 17:23
  • @Froyo ```sum=Math.sqrt(Math.pow(event.values[0],2)+Math.pow(event.values[1],2)+Math.pow(event.values[2],2)); DecimalFormat precision = new DecimalFormat("0.00"); double accRound = Double.parseDouble(precision.format(sum)); accReader.setText("Total: " + accRound); if (accRound <= 2.0){ SM.unregisterListener(this); Toast.makeText(this, "Fall detected", Toast.LENGTH_SHORT).show(); startService(new Intent(MainActivity.this, AlertService.class)); }``` giving almost same result. – sKhanm Dec 06 '19 at 17:51

0 Answers0