get Screen Resolution - Android android.app

Android examples for android.app:Screen

Description

get Screen Resolution

Demo Code

import android.content.Context;
import android.view.WindowManager;

public class Main {

  @SuppressWarnings("deprecation")
  public static int[] getResolution(Context context) {

    if (null == context) {
      return null;
    }// ww  w.j  a va2 s  . c om
    WindowManager windowMgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    int[] res = new int[2];
    res[0] = windowMgr.getDefaultDisplay().getWidth();
    res[1] = windowMgr.getDefaultDisplay().getHeight();
    return res;
  }

}

Related Tutorials