get Dpi - Android User Interface

Android examples for User Interface:Display

Description

get Dpi

Demo Code


//package com.java2s;

import android.content.Context;

import android.util.DisplayMetrics;

public class Main {
    private static Context mContext;

    public static String getDpi() {
        String info;/*from   w ww.j a v a  2  s .  c  om*/
        DisplayMetrics metric = mContext.getResources().getDisplayMetrics();

        int width = metric.widthPixels; 
        int height = metric.heightPixels; 
        float density = metric.density; 
        int densityDpi = metric.densityDpi; 
        info = "width:" + width + " height:" + height + " d:" + density
                + " dpi:" + densityDpi;
        return info;
    }
}

Related Tutorials