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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…