Android DisplayMetrics returns incorrect screen size in pixels on ICS

From the answer of Ahmed, this is full code without error: int width = 0, height = 0; final DisplayMetrics metrics = new DisplayMetrics(); Display display = getWindowManager().getDefaultDisplay(); Method mGetRawH = null, mGetRawW = null; try { // For JellyBean 4.2 (API 17) and onward if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { display.getRealMetrics(metrics); width = metrics.widthPixels; height … Read more