Android Screen Size Get getScreenDensity(Context context)

Here you can find the source of getScreenDensity(Context context)

Description

get Screen Density

Declaration

public static int getScreenDensity(Context context) 

Method Source Code

//package com.java2s;
import android.content.Context;

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

public class Main {
    private static DisplayMetrics _display_metrics = null;

    public static int getScreenDensity(Context context) {
        retrieveDisplayMetrics(context);
        return (int) (_display_metrics.density * DisplayMetrics.DENSITY_DEFAULT);
    }//from   w  ww .j a v  a2  s . co  m

    private static void retrieveDisplayMetrics(Context context) {
        if (_display_metrics == null) {
            Display display = ((WindowManager) context
                    .getSystemService(Context.WINDOW_SERVICE))
                    .getDefaultDisplay();
            _display_metrics = new DisplayMetrics();
            display.getMetrics(_display_metrics);
        }
    }
}

Related

  1. getScreenSizePixels(Context ctx)
  2. getRealScreenDimensions(Context context)
  3. getScreenHeight(Context context)
  4. getScreenSize(@Nonnull Context context)
  5. getScreenWidth(Context context)
  6. getScreenSize(Activity ctx)
  7. getScreenSize(Context context)
  8. getScreenSize(Context ctx)
  9. getMinTouchHeight(Context context)