Can i get resolution of android phone..?
if yes then how..?
it will really helpful for me..
Thank you..

- 31,226
- 9
- 68
- 81

- 1,268
- 3
- 13
- 27
8 Answers
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(); // deprecated
int 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);
}
-
2Thank you so much.. but I am using phonegap.. Is it possible to do it using javascript..? – Rikin Thakkar Jul 05 '12 at 06:26
-
Got it.. Thank you.. i m going to try it.. – Rikin Thakkar Jul 05 '12 at 06:37
-
As i am new to stackoverflow,i didn't know about this.. so thnx again for providing information.. – Rikin Thakkar Jul 05 '12 at 07:16
-
okies.. but how can i do this..? By clicking on that star..? – Rikin Thakkar Jul 05 '12 at 07:24
-
its working but doesnt include soft key navigation area. how to include this? – chip Nov 14 '13 at 09:02
For Cordova / Phonegap, I've found that using
var width = screen.width
var height = screen.height
is more reliable than using
var width = window.innerHeight
var 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.

- 1,247
- 16
- 18
-
2I agree. Just be careful on some devices the height and width don't rotate with the display. – Leo Jan 17 '13 at 00:02
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.

- 13,960
- 31
- 73
- 121
-
-
Always mention in your heading how you want to do it. So right people can help you... Chalo nice its Working for you. – coderslay Jul 05 '12 at 06:54
You can call
Display display = getWindow().getWindowManager().getDefaultDisplay();
Point outSize = new Point();
display.getRealSize(outSize);
outSize.x is the width and outSize.y is the height. Hope it help.

- 31
- 1
like this
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
look at this answer Android: How to get screen dimensions

- 1
- 1

- 22,428
- 19
- 115
- 166
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
Good luck!

- 3,275
- 2
- 26
- 38
-
Thank you so much.. but I am using phonegap.. Is it possible to do it using javascript..? – Rikin Thakkar Jul 05 '12 at 06:14
-
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
good luck 행운을 빈다.

- 113
- 13
u can get screen resolution like this
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height=display.getHeight();

- 5,746
- 10
- 47
- 74