Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.util.DisplayMetrics; import android.util.Log; import android.view.WindowManager; public class Main { private static final String TAG = "DeviceInfoUtil"; private static DisplayMetrics displayMetrics; public static int getScreenShortSize(Context context) { getScreenSize(context); return Math.min(displayMetrics.widthPixels, displayMetrics.heightPixels); } public static DisplayMetrics getScreenSize(Context context) { if (displayMetrics == null) { try { displayMetrics = new DisplayMetrics(); displayMetrics.widthPixels = 1280; displayMetrics.heightPixels = 720; WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(displayMetrics); } catch (Exception e) { Log.e(TAG, e.getMessage()); } } return displayMetrics; } }