title: How to get device raw width and height or actual screen width and height ?
body: <p>I am trying to get the actual screen width and height of the Nexus 7 running on 4.2.</p>
  
  <p>I am doing some runtime calculations based on device width and height to resize buttons and some UI elements, so it will look proper in all devices. my code was working great in all SDKs 4.1 and below but not working on 4.2.</p>
  
  <p>I am using following code to get width and height. </p>
  
  <p>Code: 1</p>
  
  <pre><code>DisplayMetrics displaymetrics = new DisplayMetrics();
  getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
  mWidth = displaymetrics.widthPixels;
  mHeight = displaymetrics.heightPixels;
  </code></pre>
  
  <p>Code: 2</p>
  
  <pre><code>Point size = new Point();
  WindowManager w = getWindowManager();
  w.getDefaultDisplay().getSize(size); 
  mWidth = size.x;
  mHeight = size.y;
  </code></pre>
  
  <p>I have also tried with undocumented methods</p>
  
  <p>Code: 3</p>
  
  <pre><code>Display display = getWindowManager().getDefaultDisplay();
  Method mGetRawW = Display.class.getMethod("getRawWidth");
  Method mGetRawH = Display.class.getMethod("getRawHeight");
  mWidth = (Integer) mGetRawW.invoke(display);
  mHeight = (Integer) mGetRawH.invoke(display);
  </code></pre>
  
  <p>But none of above is working with Nexus 7 running on 4.2, its always subtracting status bar height, I am not getting full height. </p>
  
  <p>I have used some methods to calculate status bat height but not getting proper values, </p>
  
  <pre><code>int statusBarHeight = Math.ceil(25 * context.getResources().getDisplayMetrics().density);
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>Rect rectgle= new Rect();
  Window window= getWindow();
  window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
  int StatusBarHeight= rectgle.top;
  </code></pre>
  
  <p>Is there any standard way to get actual device screen height and width?</p>