【发布时间】:2012-03-27 06:41:28
【问题描述】:
我想在 android 中检测给定的设备是平板电脑还是手机。我在模拟器中尝试了这两种,但都没有奏效。两者都在这里:
第一
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE)
{
//code
}
第二
private boolean isTabletDevice()
{
if (android.os.Build.VERSION.SDK_INT >= 11)
{
// honeycomb
// test screen size, use reflection because isLayoutSizeAtLeast is only available since 11
Configuration con = getResources().getConfiguration();
try {
Method mIsLayoutSizeAtLeast = con.getClass().getMethod("isLayoutSizeAtLeast");
Boolean r = (Boolean) mIsLayoutSizeAtLeast.invoke(con, 0x00000004); // Configuration.SCREENLAYOUT_SIZE_XLARGE
return r;
} catch (Exception x)
{
return false;
}
}
return false;
}
【问题讨论】:
-
我上面已经提到了上面我试过的两种方法,它没有用...我想从android程序中获取它,只是不使用用户代理...
标签: android device tablet screen-size android-screen