How to get screen resolution of your android device..? [duplicate]

女生的网名这么多〃 提交于 2019-11-28 20:29:12
K_Anas

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);
    }

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.

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.

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.

RajaReddy PolamReddy

like this

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth(); 
int height = display.getHeight();  

look at this answer Android: How to get screen dimensions

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;

Good luck!

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

good luck 행운을 빈다.

u can get screen resolution like this

  Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int width = display.getWidth(); 
    int height=display.getHeight();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!