开发一个通用的Andr​​oid应用程序(手机和平板) [英] Developing an universal android application (phone and tablet)

查看:117
本文介绍了开发一个通用的Andr​​oid应用程序(手机和平板)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个通用的Andr​​oid应用程序,我需要检查,如果应用程序在平板电脑或手机上运行。有没有什么方法来做到这一点?

I'm developing an universal android application and I need to check if the application is running in a tablet or in a phone. Is there any method to do it?

推荐答案

您可以查看谷歌I / O应用程序对于Android SRC code:

You can check the Google I/O App for Android src code:

在<一个href="http://$c$c.google.com/p/iosched/source/browse/android/src/com/google/android/apps/iosched/util/UIUtils.java">UIUtils类,你有以下几种方法:

In the UIUtils class you have the following methods:

public static boolean isHoneycomb() {
    // Can use static final constants like HONEYCOMB, declared in later versions
    // of the OS since they are inlined at compile time. This is guaranteed behavior.
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
}

public static boolean isTablet(Context context) {
    return (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK)
            >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

public static boolean isHoneycombTablet(Context context) {
    return isHoneycomb() && isTablet(context);
}

这篇关于开发一个通用的Andr​​oid应用程序(手机和平板)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆