Here you can find the source of getScreenSizePixels(Context ctx)
public static int[] getScreenSizePixels(Context ctx)
//package com.java2s; import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.util.DisplayMetrics; import android.view.Display; import android.view.WindowManager; public class Main { public static int[] getScreenSizePixels(Context ctx) { int widthHeightInPixels[] = new int[2]; try {//from w w w. j a va2 s . c o m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { Resources resources = ctx.getResources(); Configuration config = resources.getConfiguration(); DisplayMetrics dm = resources.getDisplayMetrics(); double screenWidthInPixels = (double) config.screenWidthDp * dm.density; double screenHeightInPixels = screenWidthInPixels * dm.heightPixels / dm.widthPixels; widthHeightInPixels[0] = (int) (screenWidthInPixels + .5); widthHeightInPixels[1] = (int) (screenHeightInPixels + .5); } else { WindowManager wm = (WindowManager) ctx .getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); widthHeightInPixels[0] = display.getWidth(); // deprecated widthHeightInPixels[1] = display.getHeight(); // deprecated } } catch (Exception e) { } return widthHeightInPixels; } }