Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid natural sensor orientation help
    primarykey
    data
    text
    <p>I am trying to accomplish Reto Meier's recommended way for keeping the screen orientation from changing. The slides from his talk during Google IO (see #23) can be found in <em><a href="http://blog.radioactiveyak.com/2011/05/android-protips-where-to-download.html" rel="nofollow">Android Protips: Where to Download the Slides and Code Snippets</a></em>.</p> <p>I have stepped through the code and it setting the values, but the screen orientation still changes. FYI, I register this listener in the Application.</p> <p>Here is my code:</p> <pre><code>final SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sm.registerListener( new SensorEventListener() { @Override public void onSensorChanged(SensorEvent sensorEvent) { if (sensorEvent.sensor.getType() == Sensor.TYPE_ORIENTATION) { final WindowManager wm = (WindowManager) getApplicationContext() .getSystemService(Context.WINDOW_SERVICE); final Display display = wm.getDefaultDisplay(); int x = SensorManager.AXIS_X; int y = SensorManager.AXIS_Y; switch (display.getRotation()) { case Surface.ROTATION_90: x = SensorManager.AXIS_Y; y = SensorManager.AXIS_MINUS_X; break; case Surface.ROTATION_180: y = SensorManager.AXIS_MINUS_Y; break; case Surface.ROTATION_270: x = SensorManager.AXIS_MINUS_Y; y = SensorManager.AXIS_MINUS_X; break; case Surface.ROTATION_0: default: break; } SensorManager.remapCoordinateSystem(sensorEvent.values, x, y, new float[] {}); } } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { } }, sm.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload