我想获取有关设备的信息,以查看它是智能手机还是平板电脑。我该怎么做?
我想根据设备类型显示来自资源的不同网页:
String s="Debug-infos:";
s += "\n OS Version: " + System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")";
s += "\n OS API Level: " + android.os.Build.VERSION.SDK;
s += "\n Device: " + android.os.Build.DEVICE;
s += "\n Model (and Product): " + android.os.Build.MODEL + " ("+ android.os.Build.PRODUCT + ")";
但是,这对我的情况似乎没用。
这个解决方案现在对我有用:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
int height = metrics.heightPixels;
if (SharedCode.width > 1023 || SharedCode.height > 1023){
//code for big screen (like tablet)
}else{
//code for small screen (like smartphone)
}