Изменение ориентации Android-устройств с помощью ADB
Я использую Android 4.4 на реальном устройстве, и я хочу настроить ориентацию устройства через adb
. Я не хочу, чтобы это было сделано с uiautomator, так как это не будет продолжаться после окончания кода uiautomator.
Как я могу это сделать?
Ответы
Ответ 1
Сначала вам нужно отключить автоматическое вращение
adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0
вращаться в альбом
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1
вращать портрет
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0
Ответ 2
Вместо использования "содержимого оболочки adb" существует более чистый способ, используя "настройки оболочки adb". Они делают то же самое, добавили ценность поставщику настроек.
adb shell settings put system accelerometer_rotation 0 #disable auto-rotate
adb shell settings put system user_rotation 3 #270° clockwise
-
accelerometer_rotation: auto-rotation, 0 disable, 1 enable
-
user_rotation: actual rotation, clockwise, 0 0°, 1 90°, 2 180°, 3 270°
Ответ 3
Отключить accelerometer_rotation
и установить user_rotation
user_rotation Values:
0 # Protrait
1 # Landscape
2 # Protrait Reversed
3 # Landscape Reversed
accelerometer_rotation Values:
0 # Stay in the current rotation
1 # Rotate the content of the screen
Пример использования adb:
adb shell settings put system accelerometer_rotation 0
adb shell settings put system user_rotation 3
Пример программно:
import android.provider.Settings;
// You can get ContentResolver from the Context
Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);
Settings.System.putInt(getContentResolver(), Settings.System.USER_ROTATION, 3);