android - 开发通用 Android 应用程序(手机和平板电脑)

标签 android

我正在开发一个通用 Android 应用程序,我需要检查该应用程序是否在平板电脑或手机中运行。有什么方法可以实现吗?

最佳答案

您可以查看 Google I/O App for Android源代码:

UIUtils类有以下方法:

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);
}

关于android - 开发通用 Android 应用程序(手机和平板电脑),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6872190/

相关文章:

android - 在 Android Studio 上自动生成单元测试 stub

Android:ContentProvider 是否将所有数据加载到游标或这只是惰性加载

android - 从另一个项目编译模块

android - 不使用 Gradle 创建的仪器测试

android - ImageButton onClick 改变颜色

java - 在两个 Activity 中共享变量?

由于 shrinkReleaseMultiDexComponents,Android 版本构建失败

安卓 GCM : understanding XMPP

android - 事件提醒不适用于 android 中的日历事件

android - 将数据从 ListView 传递到另一个 Activity