确定设备是智能手机还是平板电脑?我想了解一个设备的信息,看看它是智能手机还是平板电脑。我该怎么做?我想根据设备的类型显示与资源不同的网页: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)}
3 回答
冉冉说
TA贡献1877条经验 获得超1个赞
<resources> <bool name="isTablet">true</bool></resources>
<resources> <bool name="isTablet">true</bool></resources>
<resources> <bool name="isTablet">false</bool></resources>
boolean tabletSize = getResources().getBoolean(R.bool.isTablet);if (tabletSize) { // do something} else { // do something else}
翻阅古今
TA贡献1780条经验 获得超5个赞
DisplayMetrics metrics = new DisplayMetrics();getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); float yInches= metrics.heightPixels/metrics.ydpi;float xInches= metrics.widthPixels/metrics.xdpi; double diagonalInches = Math.sqrt(xInches*xInches + yInches*yInches);if (diagonalInches>=6.5){ // 6.5inch device or bigger}else{ // smaller device}
忽然笑
TA贡献1806条经验 获得超5个赞
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); if(manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE){ return "Tablet"; }else{ return "Mobile"; }
- 3 回答
- 0 关注
- 577 浏览
添加回答
举报
0/150
提交
取消