2013-07-12 212 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); 
}