2013-07-12 54 views

回答

0

我已经想通了。您可以使用函数调用getUiDevice(),getDisplayWidth()和getUiDevice()。getDisplayHeight()来获取设备的宽度和高度。您可以使用ADB获取像素密度:getprop ro.sf.lcd_density。然后使用公式px = dp *(dpi/160)可以生成公式dp = px /(dpi/160)。最后,根据Android的屏幕尺寸指定如下:small - 426dp x 320dp,normal - 470dp x 320dp,large - 640dp x 480dp,以及xlarge - 960dp x 720dp,其中大尺寸和xlarge尺寸的屏幕尺寸为平板电脑:)。请享用!

public boolean isTablet() throws Exception { 
    double widthpx = getUiDevice().getDisplayWidth(); 
    double heightpx = getUiDevice().getDisplayHeight(); 

    Runtime runtime = Runtime.getRuntime(); 
    Process process = runtime.exec("getprop ro.sf.lcd_density"); 

    InputStream inputStream = process.getInputStream(); 
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream); 
    BufferedReader bufferedReader = new BufferedReader(inputStreamReader); 

    double dpi = Double.parseDouble(bufferedReader.readLine()); 

    double widthdp = widthpx/(dpi/160); 
    double heightdp = heightpx/(dpi/160); 

    return (widthdp >= 640 && heightdp >= 480); 
}