How to get screen resolution of your android device..?

<>

This question already has an answer here:

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

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.


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

Need Your Help

Does Laravel's "soft_delete" need index on MySQL?

mysql optimization laravel eloquent

If i'm using soft delete in laravel 4.2 (database is mysql), every eloquent builded query has WHERE deleted_at IS NULL. There are no index on deleted_at.

Getting Spark, Python, and MongoDB to work together

python mongodb hadoop apache-spark pymongo

I'm having difficulty getting these components to knit together properly. I have Spark installed and working succesfully, I can run jobs locally, standalone, and also via YARN. I have followed the ...