Get screen size

  1. Home
  2. chevron_right
  3. Snippets
  4. chevron_right
  5. Get screen size

Get screen size

So if you ever need to get screen size in width and height on Android, you can use the following snippet:

/**
     * Returns the size of the screen in pixels (width and height)
     *
     * @return a Point that has the screen width stored in x and height in y
     */
    public Point getScreenSize(Activity context) {
        Display display = context.getWindowManager().getDefaultDisplay();
        Point size = new Point();

        if (android.os.Build.VERSION.SDK_INT >= 13) {
            display.getSize(size);
        } else {
            //noinspection deprecation
            size.set(display.getWidth(), display.getHeight());
        }

        return size;
    }

 

, , , , , ,
Previous Post
How to unzip Gzipped InputStream
Next Post
Generate random number between 2 numbers

Related Posts

Menu