# How to get Device DPI

**URL:** <https://discuss.appium.io/t/how-to-get-device-dpi/22938>\
**Category:** Support\
**Created:** [July 25, 2018, 11:56am UTC](https://discuss.appium.io/t/how-to-get-device-dpi/22938 "2018-07-25T11:56:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kfirbh](https://discuss.appium.io/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@kfirbh](https://discuss.appium.io/u/kfirbh)\
**Post date:** [July 25, 2018, 11:56am UTC](https://discuss.appium.io/t/how-to-get-device-dpi/22938/1 "2018-07-25T11:56:08Z")

</div>

Hi all  
is there any way to get the device DPI values  
without running shell ADB commands ?

---

<div class="post-metadata">

**Author:** ![mykola-mokhnach](https://discuss.appium.io/user_avatar/discuss.appium.io/mykola-mokhnach/32/4578_2.png) [@mykola-mokhnach](https://discuss.appium.io/u/mykola-mokhnach)\
**Post date:** [July 25, 2018, 2:13pm UTC](https://discuss.appium.io/t/how-to-get-device-dpi/22938/2 "2018-07-25T14:13:13Z")

</div>

UIAutomator2 driver stores such information in [capabilities](https://github.com/appium/appium-uiautomator2-driver/blob/35e55d5ccd72a871c830cacc8b62f00bdd9d4a76/lib/driver.js#L277) along with some other useful device info

---

<div class="post-metadata">

**Author:** ![kfirbh](https://discuss.appium.io/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@kfirbh](https://discuss.appium.io/u/kfirbh)\
**Post date:** [July 26, 2018, 11:28am UTC](https://discuss.appium.io/t/how-to-get-device-dpi/22938/3 "2018-07-26T11:28:03Z")

</div>

thanks  
Any idea about how to get that info from IOS?

---

<div class="post-metadata">

**Author:** ![mykola-mokhnach](https://discuss.appium.io/user_avatar/discuss.appium.io/mykola-mokhnach/32/4578_2.png) [@mykola-mokhnach](https://discuss.appium.io/u/mykola-mokhnach)\
**Post date:** [July 26, 2018, 11:44am UTC](https://discuss.appium.io/t/how-to-get-device-dpi/22938/4 "2018-07-26T11:44:18Z")

</div>

Try getSession endpoint: [https://github.com/appium/appium-xcuitest-driver/blob/15e03c8061c0d3411f7566e334a24548a191b87d/lib/driver.js#L1025](https://github.com/appium/appium-xcuitest-driver/blob/15e03c8061c0d3411f7566e334a24548a191b87d/lib/driver.js#L1025)

---

<div class="post-metadata">

**Author:** ![Smitty](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/e274bd/32.png) [@Smitty](https://discuss.appium.io/u/Smitty)\
**Post date:** [July 26, 2018, 9:23pm UTC](https://discuss.appium.io/t/how-to-get-device-dpi/22938/5 "2018-07-26T21:23:06Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![kfirbh](https://discuss.appium.io/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@kfirbh](https://discuss.appium.io/u/kfirbh)\
**Post date:** [July 29, 2018, 7:25am UTC](https://discuss.appium.io/t/how-to-get-device-dpi/22938/6 "2018-07-29T07:25:32Z")

</div>

thanks  
what you need to do if you want to access it from you JAVA code  
is to get it from SessionDetails obj in case of IOS and from device caps in case of Android

10x

---

<div class="post-metadata">

**Author:** ![Smitty](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/e274bd/32.png) [@Smitty](https://discuss.appium.io/u/Smitty)\
**Post date:** [July 30, 2018, 3:53pm UTC](https://discuss.appium.io/t/how-to-get-device-dpi/22938/7 "2018-07-30T15:53:32Z")

</div>

Good to know. Thanks!
