title: What is the alternative for getRealMetrics in android to get screen original size
body: <p>In my android application I need to find out if the device is having a navigation bar or not. For that I am getting the device original screen size and application window size. Based on that I am calculating the difference and so I can find out if the device is having a navigation bar or not.
  Here is the code I use:</p>
  
  <pre><code>public static boolean hasSoftKeys(WindowManager windowManager){
      Display d = windowManager.getDefaultDisplay();
  
      DisplayMetrics realDisplayMetrics = new DisplayMetrics();
      d.getRealMetrics(realDisplayMetrics);
  
      int realHeight = realDisplayMetrics.heightPixels;
      int realWidth = realDisplayMetrics.widthPixels;
  
      DisplayMetrics displayMetrics = new DisplayMetrics();
      d.getMetrics(displayMetrics);
  
      int displayHeight = displayMetrics.heightPixels;
      int displayWidth = displayMetrics.widthPixels;
  
      return (realWidth - displayWidth) &gt; 0 || (realHeight - displayHeight) &gt; 0;
  }
  </code></pre>
  
  <p>The problem is: Calling the "<code>getRealMetrics</code>" method requires api level 17. Here I need a solution for the lower version devices which will give the same result like <code>getRealMetrics</code> to get the original screen size. I did not find any solution.</p>
  
  <p>Can anybody suggest me any alternative for <code>getRealMetrics</code> which will work for the lower version devices ?</p>
  
  <p>Here is my investigation to find out the navigation bar availability. It is not a reliable result on all devices.</p>
  
  <p><strong>Code1:</strong></p>
  
  <pre><code>boolean hasNavBar(Context context) {
  
          boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
          boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
          return !hasMenuKey &amp;&amp; !hasBackKey;
      }
  </code></pre>
  
  <p><strong>Code2</strong></p>
  
  <pre><code>boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
  </code></pre>
  
  <p>By using this code we can check if the device has PermanentMenuKey. But it is not the meaning device which don't have PermanentMenuKey is having soft navigation bar. </p>