Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;

import android.util.DisplayMetrics;

public class Main {
    public static int[] getScreenHeightAndWidth(Activity activity) {
        int[] result = new int[2];

        try {
            DisplayMetrics displayMetrics = new DisplayMetrics();
            activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
            result[0] = displayMetrics.widthPixels;
            result[1] = displayMetrics.heightPixels;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}