3

I am developing application that is somehow similar to camera, I wish that the app will always be in landscape mode witch I achieve with:

android:screenOrientation="portrait"

But I need to know when user rotates the phone to landscape mode so I can rotate the icons 90 degrees.

I have tried:

   if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) 
    {
        Toast.makeText(getApplicationContext(), "ORIENTATION_LANDSCAPE", Toast.LENGTH_SHORT).show();

    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){

        Toast.makeText(getApplicationContext(), "ORIENTATION_PORTRAIT", Toast.LENGTH_SHORT).show();
    }

But it only works when I add:

android:configChanges="keyboardHidden|orientation|screenSize"

And its also change my orientation automatically.

So how can I keep my app always in Landscape mode and only detect when the phone is in Portrait without that phone automatically change anything? Just like in camera app

Dim
  • 4,527
  • 15
  • 80
  • 139

2 Answers2

1

Using android:configChanges="keyboardHidden|orientation|screenSize" is a good idea.

Now try setting your orientation manually:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216
0

This will help. It did for me and I needed to do exactly what you needed to do.

https://stackoverflow.com/a/5183690/687245

Community
  • 1
  • 1
louis1204
  • 401
  • 1
  • 7
  • 21