How To Change DPI (Dots Per Inch) of the Screen On Android?
DPI (Dots per Inch) is a value that Android uses to determine the ideal size of images and app icons to show on the screen. This value can be changed to get a larger, zoomed-in display or smaller display as per your needs. Check the below screenshots. The left image is at normal 480dpi, and the right one is at 200dpi. To check what the current dpi is on your phone, use the following function. It gives Empty String If something goes wrong.
private String currentDPI(AppiumDriver<WebElement> driver) {
try {
return driver.executeScript("pCloudy_executeAdbCommand", "adb shell wm density").toString();
} catch (Exception e) {
System.out.println("Something wrong while checking DPI:" + e.getMessage());
return "";
}
}
You can use this method to change the DPI. Provide your argument as int.
private void changeDPI(AppiumDriver<WebElement> driver, int value) {
try {
driver.executeScript("pCloudy_executeAdbCommand", "adb shell wm density " + value).toString();
} catch (Exception e) {
System.out.println("Something wrong while changing DPI:" + e.getMessage());
}
}