Today I have a lot of problems with sensors, but it seems that due to onSensorChanged () is not being called. Sorry for a possible duplicate question, but I have not seen any solutions. Here is my code:
public SensorManager manager;
public Sensor rotation_vector;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
manager = (SensorManager)getSystemService(SENSOR_SERVICE);
rotation_vector = manager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
}
@Override
public void onSensorChanged(SensorEvent event) {
int xValue = (int) event.values[0];
int yValue = (int) event.values[1];
int zValue = (int) event.values[2];
Toast.makeText(getApplicationContext(),"this doesn't appear...",Toast.LENGTH_LONG);
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
public void onPause() {
super.onPause();
manager.unregisterListener(this);
}
@Override
protected void onResume() {
super.onResume();
manager.registerListener(this, rotation_vector, SensorManager.SENSOR_DELAY_NORMAL);
if (null != rotation_vector) {
} else {
Toast.makeText(getApplicationContext(),
"There is no gyroscope on your device",
Toast.LENGTH_LONG).show();
}
}
I saw a lot of similar codes in different forums, but the appart from there and some other topics without solutions, I have not seen such a problem ... Do I need to add something to AndroidManifest? Is this a common problem? Is that the solution there?
Thank you Thomas (sorry for my bad English, I'm French ^^)
source
share