get Screen Density - Android android.app

Android examples for android.app:Screen

Description

get Screen Density

Demo Code

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

public class Main{

    public static float getScreenDensity(Context ctx) {
        float density = 0;
        WindowManager manager = (WindowManager) ctx
                .getSystemService(Context.WINDOW_SERVICE);
        Display defaultDisplay = manager.getDefaultDisplay();

        DisplayMetrics metrics = new DisplayMetrics();
        defaultDisplay.getMetrics(metrics);

        density = metrics.density;/*w  ww.j  a  v  a2s  .c o m*/
        return density;
    }

}

Related Tutorials