Here you can find the source of getScreenSize(Activity ctx)
public final static int[] getScreenSize(Activity 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 {/*from ww w. j av a 2s. co 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; } }