import android.provider.Settings;
public static void setAutoOrientationEnabled(Activity activity ,boolean enabled) {
try {
ContentResolver contentResolver = activity.getContentResolver();
if (android.provider.Settings.System.getInt(contentResolver, android.provider.Settings.System.ACCELEROMETER_ROTATION) == 1) {
Display defaultDisplay = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
android.provider.Settings.System.putInt(contentResolver, android.provider.Settings.System.USER_ROTATION, defaultDisplay.getRotation());
android.provider.Settings.System.putInt(contentResolver, android.provider.Settings.System.ACCELEROMETER_ROTATION, 0);
} else {
android.provider.Settings.System.putInt(contentResolver, android.provider.Settings.System.ACCELEROMETER_ROTATION, 1);
}
android.provider.Settings.System.putInt(contentResolver, android.provider.Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
}catch (android.provider.Settings.SettingNotFoundException e) {
e.printStackTrace();
}
}
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
Hiç yorum yok:
Yorum Gönder