Here you can find the source of isTabletDevice(Context activityContext)
Parameter | Description |
---|---|
activityContext | The Activity Context. |
public static boolean isTabletDevice(Context activityContext)
//package com.java2s; /*/*from w w w . j a v a2 s .c o m*/ * Copyright 2013 Nagendra K Srivastava. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.util.DisplayMetrics; public class Main { /** * <b><i>public static boolean isTabletDevice(<font color="red"><u>Context</u></font> activityContext)</b></i></p> * Checks if the device is a tablet or a phone on the basis of density and display * @param activityContext * The Activity Context. * @return Returns true if the device is a Tablet * */ public static boolean isTabletDevice(Context activityContext) { boolean xlarge = ((activityContext.getResources() .getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE); if (xlarge) { DisplayMetrics metrics = new DisplayMetrics(); Activity activity = (Activity) activityContext; activity.getWindowManager().getDefaultDisplay() .getMetrics(metrics); if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM) { // Yes, this is a tablet! return true; } } // No, this is not a tablet! return false; } }