Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 205
Rikin Thakkar Avatar asked Jul 05 '12 06:07

Rikin Thakkar


People also ask

How do I force my Android screen resolution?

Most modern Android devices will give you the option to adjust screen resolution in the Display options or Settings. To get there, look for the gear-like icon on the applications menu. It should be labeled as Settings. You can also swipe down and click on the Settings app from the drop-down menu.

How can I change my screen resolution on Android?

1 Go to the Settings menu > Display. 2 Tap on Screen resolution. 3 Select a resolution by sliding the circle. Tap on Apply once you have selected your preferred screen resolution.


1 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);     } 
like image 88
K_Anas Avatar answered Sep 19 '22 12:09

K_Anas