There are a lot of cool widgets out there that will enable and disable auto rotate on your phone. Disabling it turns it off across all apps on the phone.
Any ideas how they are accomplishing it?
Short guide: Tap the Settings icon to open the Settings app. Scroll down and tap Accessibility. Scroll down to Interaction controls and tap Auto-rotate screen to turn it off.
setRequestedOrientation(ActivityInfo. SCREEN_ORIENTATION_LANDSCAPE); Called on an activity, will lock it to landscape.
This should do the trick for you:
import android.provider.Settings; public static void setAutoOrientationEnabled(Context context, boolean enabled) { Settings.System.putInt( context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0); }
Add permission to the AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
You can find the documentation here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With