0

Hi everyone my following code works fine on samsung j7 with home button:

        mWidth = Resources.getSystem().getDisplayMetrics().widthPixels;
        mHeight = Resources.getSystem().getDisplayMetrics().heightPixels;

however on samsung a72(home button removed) i am not able to get full height of screen,actually height is 2400 (I see in manual screenshot) but result is 2170. The figure below illustrates the red area where the height cannot be taken.also how can i get the height of the above status bar? my version API 30, android 11 Thank you.

enter image description here

1 Answers1

1

I assume that:

  • your minimal version is at least HONEYCOMB (v11)
  • you use this code in a Activity-class (you need to pass any Activity instead and call the getDisplay()/getWindowManager()-method on it)

To get the height of the whole screen, use this code:

private int getRealHeight() {
    Point size = new Point();
    Display display = getWindowManager().getDefaultDisplay(); // before O (v26)
    Display display = getDisplay(); // since O (v26)
    display.getRealSize(size);
    return Math.max(size.x, size.y) // just use size.y if your screen rotation is always vertical
}

Reference: https://stackoverflow.com/a/31377616

I updated the code, because one method was deprecated.

Cactusroot
  • 1,019
  • 3
  • 16
  • Maybe my app is running in the background so i get an error "Unable to start service .... with Intent" error in line "Display display = getDisplay();" My API is 30 – Phạm Cảnh Jun 04 '21 at 13:21
  • base you i finded answer [here](https://stackoverflow.com/a/34092477/14456018). You can up for me to i can up to you. Thank you! – Phạm Cảnh Jun 04 '21 at 14:25