get Screen Rect - Android Phone

Android examples for Phone:Screen

Description

get Screen Rect

Demo Code


//package com.java2s;

import android.content.Context;

import android.graphics.Rect;

import android.view.Display;
import android.view.WindowManager;

public class Main {

    public static Rect getScreenRect(Context context) {
        if (context == null) {
            return new Rect(0, 0, 0, 0);
        }// w  w w  .  jav  a  2  s  .  c o  m
        Display display = ((WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();
        int w = display.getWidth();
        int h = display.getHeight();
        return new Rect(0, 0, w, h);
    }
}

Related Tutorials