Get display Size - Android android.view

Android examples for android.view:Display

Description

Get display Size

Demo Code

import java.lang.reflect.Method;

import android.graphics.Point;
import android.view.Display;

public class Main {

  public static void displaySize(Display display, Point outSize) {
    try {/*from  w  ww  . j  ava2s  .  c  o  m*/
      // test for new method to trigger exception
      Class<?> pointClass;
      pointClass = Class.forName("android.graphics.Point");
      Method newGetSize = Display.class.getMethod("getSize", new Class[] { pointClass });
      // no exception, so new method is available, just use it
      newGetSize.invoke(display, outSize);
    } catch (Exception ex) {
      // new method is not available, use the old ones
      outSize.x = display.getWidth();
      outSize.y = display.getHeight();
    }
  }

}

Related Tutorials