-2

I'm searching for how to get Android device diagonal screen size in inches? I've tried a lot with e.g. below links.

getting the screen density programmatically in android?

how to get android screen size programmatically, once and for all?

Community
  • 1
  • 1

2 Answers2

0

You'll get the device height and width from DisplayMetrics. Then apply Pythagoras theorem to get the diagonal measurement.

DisplayMetrics met = new DisplayMetrics();                
this.getWindowManager().getDefaultDisplay().getMetrics(met);// get display metrics object
String strSize = new DecimalFormat("##.##").format(Math.sqrt(((met.widthPixels / met.xdpi) * (met.widthPixels / met.xdpi)) + ((met.heightPixels / met.ydpi) * (met.heightPixels / met.ydpi))));

read more here

Community
  • 1
  • 1
Udit Mukherjee
  • 687
  • 5
  • 20
0

It looks you want to restrict user to use for particular screen size.

Please follow the documentation provided from the following link to distribute application based on screen size. You may need to add combinations of screen size and screen densities to filter out devices with screen size less than 4" which falls under category NORMAL.

Please note:
It would be advised to put entries in manifest so that Google Play itself filter out non compatible screen sizes.
If you programmatically check the screen size and then display a message to the user that the device is not compatible, it will be bad user experience and if its a paid app then you may need to warn user about screen size before purchasing and downloading your app.

You may need to ask your business to reconsider on the requirements on screen size!
Screens are not normally differentiated based on exact screen sizes in inches.

Abhinav Tyagi
  • 5,158
  • 3
  • 30
  • 60