android开发aosp launcher定制开发设置landscape横屏无效的解决方法

1. shell测试
  1. 先关闭自动旋转
    adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0
  2. 强制设为横屏 (1 或 3)
    adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1
2. 代码实现
//ShellUtils工具类依赖 implementation "com.blankj:utilcode:1.30.7"
//在launcher应用启动的Application里执行下面两行代码,实现方式有点取巧,因为改不了aosp代码
ShellUtils.execCmd(
    "content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0",
    false
)
ShellUtils.execCmd(
    "content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1",
    false
)
posted @ 2026-02-06 17:28  yongfengnice  阅读(2)  评论(0)    收藏  举报