I am making an application that allows you to read Wikipedia pages.
I want to display an icon every time the phone rotates from portrait to landscape or vice versa. This will allow the user to block the screen orientation if he wants, or the screen is oriented according to the sensor data. This functionality is implemented by some applications in the Google game, for example - Pocket
For this, I redefined
public void onConfigurationChanged(Configuration newConfig)
Now, if I set the locked configuration using (orientation_dir is the orientation value stored in the general settings, and this is correct, since I debugged its code).
if(orientation_dir == Configuration.ORIENTATION_LANDSCAPE) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } else if(orientation_dir == Configuration.ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); }
then the orientation is set correctly, but then when calling the phone, the ConfigurationChanged () method is not called.
If I set the orientation this way
if(orientation_dir == Configuration.ORIENTATION_LANDSCAPE) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else if(orientation_dir == Configuration.ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); }
then the desired orientation is not set. Phone reset orientation according to sensor data.
I tried not to even call super in the method, as I thought it might be wrong, but then it gives me the exception "Super not called".
I have been trying for the past 2 days and have not received any solution to this problem.
source share