is device Tablet - Android Hardware

Android examples for Hardware:Device Feature

Description

is device Tablet

Demo Code


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

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

public class Main {

    public static boolean isTablet(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();

        DisplayMetrics dm = new DisplayMetrics();
        display.getMetrics(dm);/*  w  ww  .ja v  a  2s.c om*/
        double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
        double y = Math.pow(dm.heightPixels / dm.ydpi, 2);

        double screenInches = Math.sqrt(x + y);

        return screenInches >= 6.0;
    }
}

Related Tutorials