Android Question Prevent a screen orientation?

JustinLong

Member
Licensed User
Is there a way to prevent the screen from a specific orientation?

For example, I want to use Portrait and Landscape, but i don't want ReverseLandscape and Reverse Portrait.

Is this possible?
 

Semen Matusovskiy

Well-Known Member
Licensed User
If you talk about different activities (let's say activity1 and activity2) you can set in manifest
SetActivityAttribute (activity1, android:screenOrientation, "portrait")
SetActivityAttribute (activity2, android:screenOrientation, "landscape")
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
I don't know easy way. Non-elegant way is to allow any orientation and to control changes in onConfigurationChanged (or in Activity_Create).
But really I don't understand a purpose. Reverse Portrait typically is disabled by phone settings. Why you are against "reverse landscape" ? what differense to which side the user rotates a phone - to left or to right ?
 
Last edited:
Upvote 0

JustinLong

Member
Licensed User
Its a camera app and the controls show up right next to front camera.

I'd thought about changing where the controls were, but I haven't found a way to determine if the screen is in landscape or reverse landscape.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Well, to understand orientation is enough simple. In Activity_Create is possible to retrieve getResources.getConfiguration, field orientation. In addition windowManager ().getDefaultDisplay ().getRotation ().
I can make a test app. But I am not sure that you need to do something by yourself. Take a look Erel's camera based intent.

If you want to do by yourself anyway, look carefully built-in Camera app. it works in Portrait (!). To detect real orientation and to change direction of icons, native camera app uses sensors. I am aware how to do this, because I did Camera activity, but this is enough complex.
 
Last edited:
Upvote 0
Top