3

I need to get the exactly size screen but i cant get it.

I tried this two different codes:

DisplayMetrics display = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
height = display.heightPixels;
width = display.widthPixels;


Point size = new Point();
getWindowManager().getDefaultDisplay().getSize(size);
height = size.y;
width = size.x;

In both cases the height its correct (1080) but the width its not correct. It must return 1920 but its returning 1794. Its a Samsung Galaxy S4 (1920x1080). I have a full screen app, with no actionbar or navigation bar, etc. Why is happening this and how can ai get 1920. Im using API >= 14.

Greets

user3240604
  • 407
  • 1
  • 8
  • 22

1 Answers1

2

You can try with getRealSize instead of getSize (getRealSize)

Point size = new Point();
getWindowManager().getDefaultDisplay().getRealSize(size);
height = size.y;
width = size.x;
toidv
  • 842
  • 2
  • 9
  • 19
  • I need a solution to API 14. To use that code i need API 17. It works but i need to use API 14 – user3240604 May 04 '15 at 18:03
  • You can do something like this if(Build.VESION.SDK_INT >= Build.VERSION_CODE.JELLY_BEAN_MR1) { // use getRealSize Point size = new Point(); getWindowManager().getDefaultDisplay().getRealSize(size); height = size.y; width = size.x; } else { try { Method getHeight = Display.class.getMethod("getRawHeight"); Method getWidth = Display.class.getMethod("getRawWidth"); width = (Integer) getHeight.invoke(display); height = (Integer) getWidth.invoke(display); } catch (Exception e) { width = display.getWidth(); height = display.getHeight(); } } – toidv May 05 '15 at 01:30