get Screen Type - Android Phone

Android examples for Phone:Screen

Description

get Screen Type

Demo Code


//package com.java2s;

import android.content.Context;

import android.util.DisplayMetrics;

public class Main {
    public static String getScreenType(Context mContext) {
        try {//w ww .j av  a  2s. c  om
            final int densityDpi = mContext.getResources()
                    .getDisplayMetrics().densityDpi;
            switch (densityDpi) {
            case DisplayMetrics.DENSITY_LOW:
                return "ldpi";
            case DisplayMetrics.DENSITY_MEDIUM:
                return "mdpi";
            case DisplayMetrics.DENSITY_TV:
                return "tv";
            case DisplayMetrics.DENSITY_HIGH:
                return "hdpi";
            case DisplayMetrics.DENSITY_XHIGH:
                return "xhdpi";
            case DisplayMetrics.DENSITY_XXHIGH:
                return "xxhdpi";
            default:
                return String.valueOf(densityDpi);
            }
        } catch (Throwable e) {
            return "unknown";
        }
    }
}

Related Tutorials