0

4 users using Samsung devices A52 and Tab10.1 reported that the app's playing area not filling entire screen as shown below screenshow on Samsung A52

According to GSMarena this model screen width is 1080 pixels, all the views is set to Match_Parent in xml , and getting width of any view while app running returns 810 pixel not 1080 however the views as shown fill enter screen

Below methods which i use to get screen width also all return 810 not 1080

Method 1

DisplayMetrics displayMetrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.widthPixels;

Method 2

WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getRealSize(size);
return size.x;

Method 3

return activity.getResources().getDisplayMetrics().widthPixels;

And as shown in the screenshot the bitmap created according to screen width 810 and not filling all screen

The only method which returned correct screen width is

WindowMetrics windowMetrics = activity.getWindowManager().getCurrentWindowMetrics();
Insets insets = windowMetrics.getWindowInsets().getInsetsIgnoringVisibility(WindowInsets.Type.systemBars());
return windowMetrics.getBounds().width() - insets.left - insets.right;

But after updating the game with this method , other users reported that the bitmap is now drawn in a larger area than the screen , which mean this method return 125% of their actual screen width , their devices are Samsung M62 & Samsung Note10 Lite

My question is : is their any screen scale factor that users can mess with in accessibility or something and we have to consider while getting screen width? or what causing this problem

Note that i tried the game on another A52 device and game worked correctly

  • on samsung devices it happens because of "Samsung game booster" which may run game app in reduced density environment. `getCurrentWindowMetrics` on that devices will return real device size, `getDefaultDisplay` will return size which is created by sumsung game booster environment. But we can't use deprecated `getDefaultDisplay` on android 30+ because of insets. So I have no idea how should we handle it correctly. https://stackoverflow.com/q/51014494 – ashakirov May 18 '23 at 15:19

2 Answers2

0

after 6 months of searching and trying to find why bitmap displays sometimes larger and other times smaller than ImageView in certain models however both created programmatically and using same width/height pixels I finally found a solution that worked on all the exceptions mentioned above

bitmap.setDensity(Bitmap.DENSITY_NONE);
0

DPI issues can be solved by using "drawable-nodpi" as your image resource folder.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
  • I did mean this post just the other comment; i dont have enough reputation to respond to his comment – goatlikeKarthos Sep 19 '22 at 12:52
  • 1
    You know about the commenting privilege which you do not have, so well that you can even put it into words. You are aware of the rule https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead . In that situation please do not decide to misuse a different mechanism (an answer) for something it is not meant for and which you are not allowed yet to do. So if you cannot provide your input as an answer, then please delete your answer post, and the comment beneath it. – Yunnosch Sep 19 '22 at 13:19
  • Noted. In any case my reply is a valid answer for this post; so I am going to leave it here. – goatlikeKarthos Sep 19 '22 at 14:30
  • That is why I edited as I did. Consider to improve it according to [answer], it might be perceived as more helpful. Also please take the [tour] and learn the difference between an answer (yours is very appreciated) and a comment (you cannot - yet). Also, please understand that "above" is not a reliable info on StackOverflow, your post is e.g. for me the topmost answer. Instead of "above" always use a link, which you can conveniently get by using the grey "Share" word beneath the question or the answer. – Yunnosch Sep 19 '22 at 14:37
  • the drawable is all done in code in my case , no resources to use from the resources folder, that's why bitmap.setDensity(Bitmap.DENSITY_NONE); solved my case – TripleTroop Sep 21 '22 at 14:51