28

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

K_Anas
  • 31,226
  • 9
  • 68
  • 81
Rikin Thakkar
  • 1,268
  • 3
  • 13
  • 27

8 Answers8

42

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);
    }
vee
  • 1,247
  • 16
  • 18
K_Anas
  • 31,226
  • 9
  • 68
  • 81
10

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.

vee
  • 1,247
  • 16
  • 18
  • 2
    I agree. Just be careful on some devices the height and width don't rotate with the display. – Leo Jan 17 '13 at 00:02
4

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.

coderslay
  • 13,960
  • 31
  • 73
  • 121
3

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.

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

Community
  • 1
  • 1
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
1
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;

Good luck!

Ilya Demidov
  • 3,275
  • 2
  • 26
  • 38
1

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

good luck 행운을 빈다.

Kernelzero
  • 113
  • 13
0

u can get screen resolution like this

  Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int width = display.getWidth(); 
    int height=display.getHeight();
Aamirkhan
  • 5,746
  • 10
  • 47
  • 74