Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get android device screen size?

I have two android device with same resolution

Device1 -> resolution 480x800 diagonal screen size -> 4.7 inches

Device2 -> resolution 480x800 diagonal screen size -> 4.0 inches

How to find device diagonal screen size?

Detect 7 inch and 10 inch tablet programmatically

I have used the above link but it gives both device diagonal screen size -> 5.8

like image 548
Kailas Avatar asked Oct 03 '13 09:10

Kailas


People also ask

Where can I find my phone screen size?

Screen size measurements for smartphones are calculated by measuring diagonally from the upper left-hand corner of the screen to the lower right-hand corner*. These measurements are expressed in inches.

How do you find the width of a device?

You can get the device screen width via the screen. width property. Sometimes it's also useful to use window. innerWidth (not typically found on mobile devices) instead of screen width when dealing with desktop browsers where the window size is often less than the device screen size.


2 Answers

try this code to get screen size in inch

DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int width=dm.widthPixels; int height=dm.heightPixels; double wi=(double)width/(double)dm.xdpi; double hi=(double)height/(double)dm.ydpi; double x = Math.pow(wi,2); double y = Math.pow(hi,2); double screenInches = Math.sqrt(x+y); 
like image 161
Ali Ahmad Avatar answered Sep 29 '22 03:09

Ali Ahmad


This won't work?

DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); double x = Math.pow(dm.widthPixels / dm.xdpi, 2); double y = Math.pow(dm.heightPixels / dm.ydpi, 2); double screenInches = Math.sqrt(x + y); Log.d("debug", "Screen inches : " + screenInches);  
like image 34
Smartis Avatar answered Sep 29 '22 04:09

Smartis