sunjinbo sunjinbo -5 years ago 121
Android Question

How to get the screen resolution including the size of soft keyboard?

My phone is HUAWEI NXT-AL10, and I can see its resolution is 1080 x 1920 from the system settings page, But when I try to writing some codes as below to retrieving its screen resolution, the value is 1080 x 1794, I guess maybe it doesn't include the size of soft-keyboard. So How can I get the resolution just like as the settings page said (1080 x 1920)?

DisplayMetrics metric = new DisplayMetrics();
int width = metric.widthPixels;
int height = metric.heightPixels;

Answer Source

The code below should give you what you're looking for

Point size = new Point();
iWidth = size.x;
iHeight = size.y;

Log.i(TAG, "Screen real size (pixels) :width = " + iWidth);
Log.i(TAG, "Screen real size (pixels) :height = " + iHeight);

Note that this requires API 17 and above

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download