Android examples for Phone:Screen
get Device Size Metrics
//package com.java2s; import android.content.Context; import android.util.DisplayMetrics; import android.util.Log; import android.view.WindowManager; public class Main { private static final String TAG = "DeviceUtil"; public static int getDeviceSize_Metrics(Context context, int code) { WindowManager manager = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(outMetrics); int size; int width = outMetrics.widthPixels; int height = outMetrics.heightPixels; switch (code) { case 0:/* w w w.j a v a 2s . c o m*/ size = width; break; case 1: size = height; break; default: size = width; break; } Log.i(TAG, "Device size?Width:" + width + ",Height:" + height); return size; } }