How to get screen resolution in Android Honeycomb?

后端 未结 10 1838
情深已故
情深已故 2020-12-24 09:07

I want to get real resolution of screen on Android Honeycomb.

Here\'s my code

Display display = getWindowManager().getDefaultDisplay();
int w = displ         


        
10条回答
  •  清酒与你
    2020-12-24 09:55

    Starting Andorid 3.2, the height of system status bar is not included in DisplayMetrics's height, you have to use undocumented APIs (Display.getRawWidth() and Display.getRawHeight()) to get the physical screen width or height.

    Here is the example to show you how to get the physical screen width or height.

    Method mGetRawW = Display.class.getMethod("getRawWidth");
    Method mGetRawH = Display.class.getMethod("getRawHeight");
    int nW = (Integer)mGetRawW.invoke(dp);
    int nH = (Integer)mGetRawH.invoke(dp);
    

    UPDATED: For API 13-16, you have to use the above code to get real width/height. For API 17+, you can now use the new public API, Display.getRealSize().

提交回复
热议问题