I'm having a lot of trouble tonight with sensors, but it appear it is because of onSensorChanged() is not called. Sorry for the eventual duplicate question, but I didn't see any solutions. Here's 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) {
//TODO: we'll see later about it
}
public void onPause() {
/*Et on le dés-enregistre quand on sort de l'activité, pour économiser de la batterie*/
super.onPause();
manager.unregisterListener(this);
}
@Override
protected void onResume() {
/*On enregistre le sensor quand l'utilisateur revient sur l'activité*/
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 have seen a lot of similar code on different forums, but appart from there and some others topic without solutions, I haven't seen such a problem yet... Do I have to add something in AndroidManifest ? Is it a common problem ? It there a solution ?
Thanks, Thomas (sorry for my bad english, I'm French^^)