Display display1 = getWindowManager().getDefaultDisplay();
int realWidth;
int realHeight;
if (Build.VERSION.SDK_INT >= 17){
//new pleasant way to get real metrics
DisplayMetrics realMetrics = new DisplayMetrics();
display1.getRealMetrics(realMetrics);
realWidth = realMetrics.widthPixels;
realHeight = realMetrics.heightPixels;
Log.i("sinwho","SDK >=17 RealWdith = " + realWidth + " RealHeight = " + realHeight);
} else if (Build.VERSION.SDK_INT >= 14) {
//reflection for this weird in-between time
try {
Method mGetRawH = Display.class.getMethod("getRawHeight");
Method mGetRawW = Display.class.getMethod("getRawWidth");
realWidth = (Integer) mGetRawW.invoke(display1);
realHeight = (Integer) mGetRawH.invoke(display1);
Log.i("sinwho","SDK >=14 RealWdith = " + realWidth + " RealHeight = " + realHeight);
} catch (Exception e) {
//this may not be 100% accurate, but it's all we've got
realWidth = display1.getWidth();
realHeight = display1.getHeight();
Log.i("Display Info", "Couldn't use reflection to get the real display metrics.");
}
} else {
//This should be close, as lower API devices should not have window navigation bars
realWidth = display1.getWidth();
realHeight = display1.getHeight();
Log.i("sinwho","RealWdith = " + realWidth + " RealHeight = " + realHeight);
}
}