Android capture device rotation without rotating the application

Asked

Viewed 28 times

0

I have an application with Android Webview, my Activity is configured to portrait:

<activity
        android:name=".activity.MainActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateUnspecified|adjustResize"></activity>

But I would like to take the event when the user rotates the device and the app screen continues on portrait, but I need to take this event to make an animation of just one video from inside the webview make an animation and Rotacione as well. Someone has a solution to this case?

1 answer

1


Solution found:

    SensorManager sensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE);
    sensorManager.registerListener(new SensorEventListener()
    {
        int orientation = -1;

        @Override
        public void onSensorChanged(SensorEvent event)
        {
            if (event.values[1] < 6.5 && event.values[1] > -6.5)
            {
                if (orientation != 1)
                {
                    Log.d("SensorLog", "Landscape");
                }
                orientation = 1;
            }
            else
            {
                if (orientation != 0)
                {
                    Log.d("SensorLog", "Portrait");
                }
                orientation = 0;
            }
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy)
        {
            // TODO Auto-generated method stub

        }
    }, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.