You are getting smaller size because the navigation bar takes some space, and getWindowManager().getDefaultDisplay().getMetrics(displayMetrics)
will return only available screen size.
There is no official-documented way to get the full screen size, however there are some workarounds:
- You can get the screen size after your acticity enters full-screen mode. This should hide the navbar.
You can get the size of the navbar and add it to the screen size you got in your code:
Resources resources = context.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId);
}
return 0;
You can get the whole screen size:
public static Point getRealScreenSize(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size = new Point();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealSize(size);
} else if (Build.VERSION.SDK_INT >= 14) {
try {
size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
} catch (NoSuchMethodException e) {}
}
return size;
}
Methods 2 and 3 are hacks, so keep in mind that they have a chance to fail on some devices.