How to get android device screen size?
android, android-screen
Solution
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);
Problem
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