Here you can find the source of getScreenSize(Context ctx)
public final static int[] getScreenSize(Context ctx)
//package com.java2s; //License from project: Apache License import android.app.Activity; import android.content.Context; import android.util.DisplayMetrics; public class Main { public final static int[] getScreenSize(Context ctx) { int[] screenSize = new int[2]; try {// w w w . j a v a 2 s . c o m DisplayMetrics displayMetrics = ctx.getResources() .getDisplayMetrics(); screenSize[0] = displayMetrics.widthPixels < displayMetrics.heightPixels ? displayMetrics.widthPixels : displayMetrics.heightPixels; screenSize[1] = displayMetrics.widthPixels > displayMetrics.heightPixels ? displayMetrics.widthPixels : displayMetrics.heightPixels; } catch (Exception e) { e.printStackTrace(); } return screenSize; } public final static int[] getScreenSize(Activity ctx) { int[] screenSize = new int[2]; DisplayMetrics displayMetrics = new DisplayMetrics(); ctx.getWindowManager().getDefaultDisplay() .getMetrics(displayMetrics); screenSize[0] = displayMetrics.widthPixels; screenSize[1] = displayMetrics.heightPixels; return screenSize; } }