Code example for Field

Methods: getInt

0
     */ 
    public static int getDensityDpi(DisplayMetrics metrics) {
        int density = DENSITY_MEDIUM;
        try { 
            Field densityDpiFiled = DisplayMetrics.class.getField("densityDpi");
            switch (densityDpiFiled.getInt(metrics)) {
            case DisplayMetrics.DENSITY_HIGH:
                density = DENSITY_HIGH;
                break; 
            case DisplayMetrics.DENSITY_LOW:
                density = DENSITY_LOW;
                break; 
            case DisplayMetrics.DENSITY_MEDIUM:
                density = DENSITY_MEDIUM;
                break; 
            } 
        } catch (NoSuchFieldException e) {
            // Just pass, we are dealing with an older device. 
            Log.d(TAG, "Older device, using DENSITY_MEDIUM.");
        } catch (IllegalArgumentException e) {
Stop searching for code, let great code find you!  Add Codota to your java IDE