Calculate the height and width (in centimetres or inches) of the mobile phone/ tablet screen

Hi, I would like to create an app which can measure the height and width of the mobile phone/ tablet screen. Request if someone could let me know an extension I could use to accomplish this.

You do not need an extension. Look at the blocks for Screen1 in your project, you will find Screen1.Height and Screen1.Width.

Thanks for your reply. The screen1.height and screen1.width returns the height and width in terms of pixels and not inches/ centimetres. Is there anyway of converting pixels to centimetres or inches?

Google says there are 38 px in 1 cm.

You can get close....

AppInventor screen width and height are determined by a dpi of 160, therefore by dividing the outputs of width and height you can get close. However if your device has soft control buttons then this, and the status bar at the top need to be added back.

On my Google Pixel 4A I used these blocks

which returns:

Width:      2.45ins (measured - 2.42ins)
Height:     5.35ins (measured - 5.47ins)
Diagonal:   5.88ins (spec - 5.8ins)

Is close enough, good enough ?
YMMV - and you might come up with something better....

Thanks a lot. This is very helpful

Here are some values and calculations of a → displayMetrics extension with a Galaxy Note8:

To get the (visible) diagonal in inches or cm:

Extension seems to show wrong here as it forgot to include navigationbar..

bild

1 Like

This value comes from DisplayMetrics and does not include the status bar (and as far as I know also the navigation bar).

    public int HeightPixels() {
        return this.context.getResources().getDisplayMetrics().heightPixels;
    }

As you can see the Screen.Hight block returns the same value in this case (Galaxy Note8).

But on a Pixel 2XL:

These need to be added back to give the correct height.

You could try changing orientation and get the width again ( in landscape, which will be the height in portrait). I tried this with my simple method, but it returned the same number.

Only navigationbar

48dp
192px

692+48=740
2768+192=2960

740*4=2960

So you mean Google (DisplayMetrics) is getting it wrong.

I believe it may be returning "usable display", like what AppInventor does....

Yes, so it only returns the available screen height.
grafik

Since the navigation bar always has 48dp, the calculation is very simple.

Pixel 2XL:

True however this will only work on soft navigationbar..

P.S. in the near future we will not have to worry about this hardware navigationbar as they will be obsolete..