Screen size: height and width doesn’t match phone resolution

I need to get the screen size of the phone for my App. I try to use the screen property: width and height. However, the size I get is wrong :frowning:

I had a look to the different post such as: https://community.appinventor.mit.edu/t/screen-height-and-width-doesnt-match-phone-resolution-using-responsive-size/19168, but did not find the real answer.

I am using the timer as described, and I also trried to set ShowStatusBar and TitleVisible to False or True, but changing this parameter does not change the result.

My phone is a Xiaomi Mi11 Ultra with a screen resoultion of 1440x3200. The screen size I get is 831x411 (with ShowStatusBar and TitleVisible enabled or disabled). According to the post, size is not in pixel but in dp (that's OK, but the odcumention says it is in pixel)
image

However, even if I try to convert dp in pixel: using 515 dpi for my phone, I get 831 x (515 / 160) = 2680 instead of 3440, and 411 x (515 / 160) = 1322 instead of 1440.

Difference could be because of the "usable" screen size, but it should change when hide/show title and status bar ?

Here is my test program (using Responsive Size):
ScreenSizeTest.aia (7.0 KB)

and the screenshots with and without title / staus bar:


Thanks for your help

Thanks a lot Anke. This extension provides the results I was expecting :grinning:
At least App Inventor help for screen parameters should be updated, so it says result is in dp (good explanation here ), and would be good to point to this DisplayMetrics extension

This extension returns 560dpi for my screen (Xiaomi Mi11 Ultra), while the doc on the web says 515dpi.

Any idea why it is different?

Thanks

From my point of view, you are better off working with the default reported sizes. Otherwise you may need to change the sizings using the extension for every component you use.

You then can correctly size images for most devices if you work on that basis, instead of fiddling about with dp/pixels. viz: a 4:3 aspect ratio image, viewed with phone in portrait mode, needs to be no larger than 411w x 308h. (probably easier to resize to 400x300 on your device :wink: )

831x411 is fairly standard for most phones, my Pixel 4a is 753 x 392, roughly 2:1 aspect.

Device Settings: "Display size" (Google Pixel 4XL, Android 13):

Sorry, I do not understand your screenshot. Are these values for different phones? How do you get these different results?
My worry is that the 560 dpi returned by the extension is different from the screen datasheet which is 515.
image

No. (But I used different "Display Sizes".

I really feel stupid, but how do you change Display Size? Screen Width and Height are hardware phone parameters, and using Responsive screen sizing, my understanding is that app will adapt to the hardware resolution, but will be fixed for a given phone
Seems I do not understand something

OK, Got it. It is not in App Inventor but in phone setup.

I have two different resolution available on my phone WQHD+: 3200x1440 or FHD+: 2400x1080.

For the FHD+ I get a dpi of 420, and for WQHD+ I get 560.

What I do not understand is this 560 for full resolution 3200x1440, versus 515 of the display specification

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.