确定该设备是智能手机或平板电脑?智能手机、平板、设备、电脑

2023-09-11 10:56:37 作者:ふダ_独特

我想获得的信息有关的设备,看它是否是一个智能手机或平板电脑。我该怎么办呢?

我想告诉从资源基于设备的类型,不同的网页:

 的String =调试-的相关信息:;
S + =\ñOS版本:+ System.getProperty(os.version)+(+ android.os.Build.VERSION.INCREMENTAL +);
S + =\ N 2 OS API级别:+ android.os.Build.VERSION.SDK;
S + =\ñ设备:+ android.os.Build.DEVICE;
S + =\ñ模型(和产品):+ android.os.Build.MODEL +(+ android.os.Build.PRODUCT +);
 

不过,好像没用了我的情况。

该解决方案现在为我的作品:

  DisplayMetrics指标=新DisplayMetrics();
。getWindowManager()getDefaultDisplay()getMetrics(度量)。
INT宽度= metrics.widthPixels;
INT高= metrics.heightPixels;

如果(共享code.width> 1023 ||共享code.height> 1023){
   // code为大屏幕(如平板电脑)
}其他{
   // code为小屏幕(如智能手机)
}
 
5.3大屏正品双核超薄安卓智能手机平板电脑男女学生微信手机

解决方案

本课题是在Android培训讨论:

http://developer.android.com/training/multiscreen/screensizes.html#TaskUseSWQuali

如果你读了整个话题,他们解释如何设置一个特定的值,文件中的布尔值(RES /值-sw600dp /):

 <资源>
    <布尔名=isTablet>真< /布尔>
< /资源>
 

由于该sw600dp预选赛仅适用于Android 3.2以上平台。如果你想确保这种技术适用于所有平台(3.2之前),创建RES /价值观XLARGE文件夹中的同一个文件:

 <资源>
    <布尔名=isTablet>真< /布尔>
< /资源>
 

那么,在标准值文件(如RES /价值/),您将布尔为false:

 <资源>
    <布尔名=isTablet>假< /布尔>
< /资源>
 

然后,在你的活动,你可以得到这个值和检查,如果你在一个平板大小的设备上运行:

 布尔tabletSize = getResources()getBoolean(R.bool.isTablet)。
如果(tabletSize){
    // 做一点事
} 其他 {
    //做别的事情
}
 

I would like to get info about a device to see if it's a smartphone or tablet. How can I do it?

I would like to show different web pages from resources based on the type of device:

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 + ")";

However, it seems useless for my case.

This solution works for me now:

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

解决方案

This subject is discussed in the Android Training:

http://developer.android.com/training/multiscreen/screensizes.html#TaskUseSWQuali

If you read the entire topic, they explain how to set a boolean value in a specific value file (as res/values-sw600dp/):

<resources>
    <bool name="isTablet">true</bool>
</resources>

Because the sw600dp qualifier is only valid for platforms above android 3.2. If you want to make sure this technique works on all platforms (before 3.2), create the same file in res/values-xlarge folder:

<resources>
    <bool name="isTablet">true</bool>
</resources>

Then, in the "standard" value file (as res/values/), you set the boolean to false:

<resources>
    <bool name="isTablet">false</bool>
</resources>

Then in you activity, you can get this value and check if you are running in a tablet size device:

boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
    // do something
} else {
    // do something else
}