1

I have a WebView embedded in a Fragment. In the manifest file, I have declared that the activity will handle orientation changes:

android:configChanges="orientation|screenSize"

and in the Activity, I have over-ridden onConfigurationChanged() in order to capture the orientation.

I thought this means that we have to explicitly take care of any changes in the screen orientation. But what I see is that the screen is still rotated (although the activity is not re-created).

If I use the following line:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

it does prevent the screen from being rotated, but I don't get the rotation event.

So, in short, I don't want the system to rotate the screen, and at the same time, I want to get an event from the system that the orientation has changed from portrait to landscape.

Thanks,
Rajath

rajath
  • 11,154
  • 6
  • 40
  • 59
  • If you prevent the screen rotation, what do you mean "still getting the rotation event"? Those statements seem contradictory to me. – Stochastically Jun 03 '13 at 10:05
  • @Stochastically, I've edited the question again to be clearer :-) Sorry for the misunderstanding – rajath Jun 03 '13 at 10:18

2 Answers2

1

If you override onConfigurationChanged(Configuration newConfig), you should be able to handle the changes.

Neron T
  • 369
  • 2
  • 8
0

Thanks for editing the question, what you're after is now clear to me. I've got two suggestions

  1. Screen orientation (i.e. portrait, landscape, reversePortrait, reverseLandscape, etc) just depends on orientation of the device in 3D space. So one idea is to capture the 3D orientation of the device yourself, which is the same information that the operating system uses to make the screen orientation decision. This means that you need to capture the accelerometer and the magnetic field sensor readings. One example of capturing that information is in my answer to Android Compass that can Compensate for Tilt and Pitch.
  2. Alternatively, you might try setting up a dummy activity that exists purely to capture the screen orientation information. That activity could sit on the activity stack behind your main activity. Although I'm not sure whether activities that aren't on top of the activity stack are notified of screen orientation changes.
Community
  • 1
  • 1
Stochastically
  • 7,236
  • 5
  • 28
  • 57
  • #1 sounds like a good idea to capture the orientation. And I can use this if I preclude the screen from rotating at all (using setRequestedOrientation), but now the problem is that the system bars also don't rotate. – rajath Jun 05 '13 at 10:45
  • #2 won't be possible, since only the active Activity would get any orientation events from the system. – rajath Jun 05 '13 at 10:46