Hi all
is there any way to get the device DPI values
without running shell ADB commands ?
created
Jul '18
last reply
Jul '18
- 6
replies
- 404
views
- 3
users
- 2
links
Hi all
is there any way to get the device DPI values
without running shell ADB commands ?
UIAutomator2 driver stores such information in capabilities8 along with some other useful device info
An Alternative:
I have some code that does a comparison between WebView pixels and Native View pixels… I am not absolutely sure this gets you hardware DPI but, in my experience using it, I think it does (I would appreciate someone correcting me if I am wrong)
Java:
AppiumDriver appDriver = <something passed into the method... can be AndroidDriver or IOSDriver at runtime>
Set<String> contextNames = ((AppiumDriver) appDriver).getContextHandles();
for (String contextName : contextNames) {
if (contextName.contains("NATIVE")) {
((AppiumDriver<MobileElement>) appDriver).context(contextName);
}
}
double screenWidth = appDriver.manage().window().getSize().getWidth();
double screenHeight = appDriver.manage().window().getSize().getHeight();
Good Luck!