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?