Search code examples
androidorientationscreen-rotationonconfigurationchanged

How to get event notification on orientation change from Landscape Left to LandScape Right?


I have an Activity which override public void onConfigurationChanged(Configuration newConfig) method. It receive event when user change orientation from landscape to portrait or from portrait to landscape . But don't show any event when i change orientation Landscape Right to Landscape Left or Landscape Left to Landscape Right. Is there any way to get even while changing orientation Landscape to Landscape ??


Solution

  • You can detect rotation side with accelerometer. When you are certain of some orientation landscape/portrait set the current angle. If orientation is changed calculate the difference to see if its 90>(roughly) and if it is, obviously screen was rotated from portrait to potrait or landscape to landscape. With that calculation you could also detect was the rotation made by the left or the right side. You get the point. Also check these answers:

    https://stackoverflow.com/a/10383164/5577679

    how to detect orientation of android device?

    Get rotation and display in degrees

    And sensors overview:

    https://developer.android.com/guide/topics/sensors/sensors_overview.html