前言
之前用自动精灵操作手机的时候,需要修改手机的分辨率,后来发现用ADB工具可以免root修改
ADB方式修改
前置操作
1、用adb工具连接手机,记得开启usb调试模式
2、执行命令,进入shell模式
adb shell
分辨率设置命令
wm size [reset|WxH|WdpxHdp]
return or override display size. width and height in pixels unless suffixed with 'dp'.
查看分辨率:wm size
修改分辨率:wm size 1440x2560
还原初设置:wm size reset
测试机:华为 FRD-DL00
Microsoft Windows [版本 10.0.18363.1500]
(c) 2019 Microsoft Corporation。保留所有权利。
C:\Users\xxx>adb shell
HWFRD:/ $ wm size // 查看
Physical size: 1080x1920 // 返回默认值
HWFRD:/ $ wm size 1440x2560 // 设置为 1440x2560
HWFRD:/ $ wm size // 重新查看
Physical size: 1080x1920 // 硬件默认值
Override size: 1440x2560 // 重写输入的值
HWFRD:/ $ wm size reset // 还原默认值
HWFRD:/ $ wm size // 重新查看
Physical size: 1080x1920 // 已被还原的硬件默认值
屏幕密度
wm density [reset|DENSITY]
查看密度:wm density
修改密度:wm density 480
还原设置:wm density reset
测试机:华为 FRD-DL00
Microsoft Windows [版本 10.0.18363.1500]
(c) 2019 Microsoft Corporation。保留所有权利。
C:\Users\xxx>adb shell
HWFRD:/ $ wm density // 查看
Physical density: 480 // 返回默认值
HWFRD:/ $ wm density 320 // 设置为 320
HWFRD:/ $ wm density // 重新查看
Physical density: 480 // 硬件默认值
Override density: 320 // 重写输入的值
HWFRD:/ $ wm density reset // 还原默认值
HWFRD:/ $ wm density // 重新查看
Physical density: 480 // 已被还原的硬件默认值
遇到的问题
使用小米手机时,可能遇到无权限的报错
Security exception: Must hold permission android.permission.WRITE_SECURE_SETTINGS
dandelion:/ $ wm density 480
Security exception: Must hold permission android.permission.WRITE_SECURE_SETTINGS
java.lang.SecurityException: Must hold permission android.permission.WRITE_SECURE_SETTINGS
at com.android.server.wm.WindowManagerService.clearForcedDisplaySize(WindowManagerService.java:5687)
at com.android.server.wm.WindowManagerShellCommand.runDisplaySize(WindowManagerShellCommand.java:156)
at com.android.server.wm.WindowManagerShellCommand.onCommand(WindowManagerShellCommand.java:62)
at android.os.ShellCommand.exec(ShellCommand.java:111)
at com.android.server.wm.WindowManagerService.onShellCommand(WindowManagerService.java:1191)
at android.os.Binder.shellCommand(Binder.java:881)
at android.os.Binder.onTransact(Binder.java:765)
at android.view.IWindowManager$Stub.onTransact(IWindowManager.java:2574)
at com.android.server.wm.WindowManagerService.onTransact(WindowManagerService.java:1432)
at android.os.Binder.execTransactInternal(Binder.java:1021)
at android.os.Binder.execTransact(Binder.java:994)
解决办法
打开下开发者选项中的USB调试(安全设置)就行了。
其他命令
HWFRD:/ $ wm
usage: wm [subcommand] [options]
wm size [reset|WxH|WdpxHdp]
wm density [reset|DENSITY]
wm overscan [reset|LEFT,TOP,RIGHT,BOTTOM]
wm scaling [off|auto]
wm screen-capture [userId] [true|false]
wm size: return or override display size.
width and height in pixels unless suffixed with 'dp'.
wm density: override display density.
wm overscan: set overscan area for display.
wm scaling: set display scaling mode.
wm screen-capture: enable/disable screen capture.
wm dismiss-keyguard: dismiss the keyguard, prompting the user for auth if necessary.
wm surface-trace: log surface commands to stdout in a binary format.
来源:https://www.jianshu.com/p/bd91b611b212
标签:android,java,density,wm,ADB,HWFRD,Android,分辨率,size From: https://www.cnblogs.com/mingyue5826/p/17782315.html