Android Device Information Get getDeviceType(Context ctx)

Here you can find the source of getDeviceType(Context ctx)

Description

get Device Type

License

Open Source License

Declaration

public static String getDeviceType(Context ctx) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Created by Carlos Yaconi//  www .  ja  va2 s.co m
 * Copyright 2012 Fork Ltd. All rights reserved.
 * License: GPLv3
 * Full license at "/LICENSE"
 ******************************************************************************/

import android.app.Activity;
import android.content.Context;

import android.util.DisplayMetrics;

public class Main {
    public static String getDeviceType(Activity act) {
        return getDeviceType(act.getApplicationContext());
    }

    public static String getDeviceType(Context ctx) {
        if (isTablet(ctx))
            return "Tablet";
        else
            return "Phone";
    }

    public static boolean isTablet(Context ctx) {
        try {
            DisplayMetrics dm = ctx.getResources().getDisplayMetrics();
            float screenWidth = dm.widthPixels / dm.xdpi;
            float screenHeight = dm.heightPixels / dm.ydpi;
            double size = Math.sqrt(Math.pow(screenWidth, 2)
                    + Math.pow(screenHeight, 2));
            return size >= 6;
        } catch (Throwable t) {
            return false;
        }
    }
}

Related

  1. getDeviceModel()
  2. getDeviceCpuCores()
  3. getDeviceUniqueIdentificator( @Nonnull Context context, @Nonnull String appId)
  4. deviceBeRoot()