Android Screen Size Get getScreenSize(Context ctx)

Here you can find the source of getScreenSize(Context ctx)

Description

get Screen Size

License

Apache License

Declaration

public final static int[] getScreenSize(Context ctx) 

Method Source Code

//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;
    }
}

Related

  1. getScreenSize(@Nonnull Context context)
  2. getScreenWidth(Context context)
  3. getScreenDensity(Context context)
  4. getScreenSize(Activity ctx)
  5. getScreenSize(Context context)
  6. getMinTouchHeight(Context context)
  7. getMinTouchWidth(Context context)
  8. getDisplayHeight(Context context)
  9. getDisplayMetrics(Context context)