This is my first question in SO so I'll accept all the critics to improve my question.
I am developing an Android App that needs to measure the distance to an object from the camera ( external camera, always in the same place ), with the help of others questions on this site I achieved this functionality on my Huawei P9, but when I try it on other devices the sensor doesn't call onSensorChanged(SensorEvent event)
.
I need this function to be called because I need the XYZ from the event .
This is how I declare my sensor and register it.
Sensor accelerometer;
accelerometer = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sm.registerListener(new SensorEventListener()
{
@Override
public void onSensorChanged(SensorEvent event)
{
setXYZ(event.values[0], event.values[1], event.values[2]);
int rotation = (int) Math.round(Math.toDegrees(Math.atan2(x, y)));
if(checkDistance)
{
distance = getDistance();
distanceOutput.setText(distance + "m");
distanceAngleOutput.setText("Angle: " + distanceAngle);
}
if(checkHeight)
{
height = getHeight();
heightOutput.setText(height + "m");
heightAngleOutput.setText("Angle: " + heightAngle);
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy)
{
// nothing here
}
}, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
Any change or information you need in order to understand my problem I'll try to provide it to you.