Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use the following:</p> <pre><code> DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); double x = Math.pow(mWidthPixels/dm.xdpi,2); double y = Math.pow(mHeightPixels/dm.ydpi,2); double screenInches = Math.sqrt(x+y); Log.d("debug","Screen inches : " + screenInches); </code></pre> <p>When mWidthPixels and mHeightPixels are taken from below code</p> <pre><code>private void setRealDeviceSizeInPixels() { WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); DisplayMetrics displayMetrics = new DisplayMetrics(); display.getMetrics(displayMetrics); // since SDK_INT = 1; mWidthPixels = displayMetrics.widthPixels; mHeightPixels = displayMetrics.heightPixels; // includes window decorations (statusbar bar/menu bar) if (Build.VERSION.SDK_INT &gt;= 14 &amp;&amp; Build.VERSION.SDK_INT &lt; 17) { try { mWidthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(display); mHeightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(display); } catch (Exception ignored) { } } // includes window decorations (statusbar bar/menu bar) if (Build.VERSION.SDK_INT &gt;= 17) { try { Point realSize = new Point(); Display.class.getMethod("getRealSize", Point.class).invoke(display, realSize); mWidthPixels = realSize.x; mHeightPixels = realSize.y; } catch (Exception ignored) { } } </code></pre> <p>See this post for reference: <a href="https://stackoverflow.com/questions/1016896/how-to-get-screen-dimensions/15699681#15699681">Get screen dimensions in pixels</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload