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 {
    private static float DEVICE_DENSITY = 0;

    public static void getDensity(Activity activity) {
        if (DEVICE_DENSITY == 0) {
            DisplayMetrics metrics = new DisplayMetrics();
            float density = metrics.density;

            activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
            DEVICE_DENSITY = metrics.density;
        }
    }
}