I am a novice in this field. My goal is to make an android application, when in a vehicle, it is used to measure speed of the vehicle using android in-built sensors. The problem I am facing is I can get acceleration using TYPE_LINEAR_ACCELERATION. But it shows on 3 different values of 3 axis. What I can understand is for this application, I should see if the mobile is in horizontal position then I should consider Y axis and if the mobile is in horizontal position then I should take X axis. But how can I know if the mobile is in horizontal or vertical position? Can someone please help me in this?
It is showing me errors, i just copied your given code: public void onSensorChanged(SensorEvent sensorEvent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){
display?.rotation
}else{
windowManager.defaultDisplay.orientation
}
float x=sensorEvent.values[0];
float y=sensorEvent.values[1];
float z=sensorEvent.values[2];
accelerationCurrentValue=Math.abs((Math.sqrt((x*x)+(y*y)+(z*z))-9.8));
accelerationCurrentValue=(double)Math.round(accelerationCurrentValue*1000)/1000;
//update text views
tv_accel.setText(String.valueOf(accelerationCurrentValue));
}
It is showing me errors Cannot resolve symbol "display","rotation","windowManager" Can you tell me how to resolve them?