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 ??
Asked
Active
Viewed 1,081 times
0

Md. Sulayman
- 781
- 8
- 30
1 Answers
1
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
-
thanks for your solution. Actually i needed event on onConfigurationChange . Is it possible?? – Md. Sulayman May 18 '17 at 10:37
-
You can put your logic based on what I wrote wherever you want. Meaning it could be also in onConfigurationChanged. If by event you mean on something like listener for side rotation as a part of onConfigurationChanged interface then there isn't anything like that. That's the main reason I wrote you the solution based on accelerometer. Otherwise I don't think that you wouldn't be even asking a question here or would these people in links I posted go through all that trouble for getting something they can get by interface method. My answer is the only solution for your question I'm afraid. – tompadre May 18 '17 at 11:46
-
The 3rd link will solve my problem I think. I will use onConfiguration change as I did earlier. If my unusual change occured I will track that onSensor changed and use an interface for callback and change as needed. Thank you – Md. Sulayman May 18 '17 at 11:51
-
No problem. I'm glad it helped! – tompadre May 18 '17 at 11:55