简体   繁体   English

Android 4.0+平板电脑关键字?

[英]Android 4.0+ tablet keyword?

I heard that there is a keyword or method that Android developers can use to determine whether Android 4.0+ is running on a tablet (without having to do any kludgy screen size comparisons). 我听说Android开发人员可以使用一种关键字或方法来确定Android 4.0+是否在平板电脑上运行(无需进行任何繁琐的屏幕尺寸比较)。 I can't find it. 我找不到

So, is this true? 那么,这是真的吗? If so, what is it? 如果是这样,那是什么?

Edit: I see that people are giving me answers that are not what I'm looking for. 编辑:我看到人们给我的答案不是我想要的。 I already know how to determine whether a device is a tablet or phone using the kludgy screen size method and using the OS method. 我已经知道如何使用kludgy屏幕尺寸方法和OS方法来确定设备是平板电脑还是手机。 I'm looking for a method that has been available starting with API level 14 that will tell me the same information -- hopefully. 我正在寻找一种从API级别14开始可用的方法,该方法可以告诉我相同的信息-希望如此。 I can't find it, so I'm wondering whether it even exists. 我找不到它,所以我想知道它是否存在。

Tablet basically just means a big(er) screen, so it comes down to that. 平板电脑基本上只意味着更大的屏幕,所以可以归结为这一点。 There's an easy way of seeing if it's a tablet sized screen or not: 有一种简单的方法可以查看它是否为平板电脑大小的屏幕:

if ( getResources().getConfiguration().isLayoutSizeAtLeast( Configuration.SCREENLAYOUT_SIZE_XLARGE ) )
{
    //Is a tablet.
}

You could change Configuration.SCREENLAYOUT_SIZE_XLARGE to Configuration.SCREENLAYOUT_SIZE_LARGE if you want to catch smaller ones too. 您也可以将Configuration.SCREENLAYOUT_SIZE_XLARGE更改为Configuration.SCREENLAYOUT_SIZE_LARGE

As described in the android documentation, the SDK level (integer) the phone is running is available in: 如android文档中所述,手机正在运行的SDK级别(整数)在以下位置可用:

android.os.Build.VERSION.SDK_INT; android.os.Build.VERSION.SDK_INT;

The enum corresponding to this int is in the android.os.Build.VERSION_CODES class. 与此int对应的枚举位于android.os.Build.VERSION_CODES类中。

Code example: 代码示例:

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.FROYO){
    // Do something for froyo and above versions
} else{
    // do something for phones running an SDK before froyo
}

Edit: This SDK_INT is available since Donut (android 1.6 / API4) so make sure your application is not retro-compatible with Cupcake (android 1.5 / API3) when you use it or your application will crash (thanks to Programmer Bruce for the precision). 编辑:此SDK_INT自Donut(android 1.6 / API4)开始可用,因此请确保您使用的应用程序与Cupcake(android 1.5 / API3)不兼容,否则应用程序将崩溃(感谢Programmer Bruce提供的精度) 。

Link 链接

Android 4+ has the configuration object . Android 4+具有配置对象 You can use the "isLayoutSizeAtLeast(int size)" method to do your check. 您可以使用“ isLayoutSizeAtLeast(int size)”方法进行检查。 It's less kludgy than some other examples I've seen around. 与我在周围看到的其他一些例子相比,它不那么笨拙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM