get Screen Size - Android android.app

Android examples for android.app:Screen

Description

get Screen Size

Demo Code

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

public class Main {

  /**//from   ww  w .j  a  v  a  2 s  .co  m
   * Method that get the Screen Size
   * 
   * @param activity
   *          Actual Activity
   * @return array type int
   */
  public static int[] getScreenSize(Activity activity) {

    // Obtain default display
    Display display = activity.getWindowManager().getDefaultDisplay();
    Point size = new Point();

    // Set Size in case of ICS
    if (android.os.Build.VERSION.SDK_INT >= 13) {
      display.getSize(size);
      return new int[] { size.x, size.y };
    } else {
      return new int[] { display.getWidth(), display.getHeight() };
    }
  }

}

Related Tutorials