How to get screen resolution of your android device..? [duplicate]
If you want the display dimensions in pixels you can use getSize:
Display display = getWindowManager().getDefaultDisplay();Point size = new Point();display.getSize(size);int width = size.x;int height = size.y;
This method was introduced in Android API 13, so if you want to get display metrics for previous APIs use:
DisplayMetrics displaymetrics = new DisplayMetrics();getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);int height = displaymetrics.heightPixels;int wwidth = displaymetrics.widthPixels;
If you're not in an Activity, you can get the default Display via WINDOW_SERVICE
. Also be sure to set your minSdkVersion to at least 4 in AndroidManifest.xml to enable calls to display.getWidth().
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);Display display = wm.getDefaultDisplay();int width = display.getWidth(); // deprecatedint height = display.getHeight(); // deprecated
Edit: PhoneGap
Use the following to figure out the display size in pixels
function getDeviceDimention() { console.log("Device Dimention using PhoneGap"); console.log("Width = " + window.innerWidth); console.log("Height = " + window.innerHeight); }
For Cordova / Phonegap, I've found that using
var width = screen.widthvar height = screen.height
is more reliable than using
var width = window.innerHeightvar height = window.innerWidth
in order to obtain the resolution of the current display. The latter is unfortunately inaccurate if your mark-up either overflows or does not take up all of the space available on the screen.
For phonegap you can use this
You can use device-width and device-height
<meta name="viewport" content="width=device-width; user-scalable=no" />
You can even get device height and width using jquery & jquery mobile like this
var width = $(window).width();var height = $(window).height();
NOTE:- Do this when device is ready.