1

I have the following code to find the size of the screen:

WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
    Point size = new Point();
    int measuredWidth = 0;
    int measuredHeight = 0;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        wm.getDefaultDisplay().getSize(size);

        measuredWidth = size.x;
        measuredHeight = size.y;
    } else {
        Display display = wm.getDefaultDisplay();

        measuredWidth = display.getWidth();
        measuredHeight = display.getHeight();
    }

On a galaxy gio (2.3.6) this works, but on a galaxy tab 10.1 (3.0) this crashes.

wm.getDefaultDisplay().getSize(size);

On this line I get

NoSuchMethodError: android.view.Display.getSize.

How can I fix this?

2

I already found it, I tought that the getSize() method was available since HoneyComb (api 11), but it's actually only available since Honeycomb_MR2 (api 13).

0

getSize() is since API 13 docs

You probably run this on a device having an older version.

Try getHeight() and getWidth().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.