有没有一种使用Android的uiautomator来检测正在测试的设备是手机还是平板电脑的方法?
提前致谢。
我已经知道了。您可以使用函数getUiDevice()。getDisplayWidth()和getUiDevice()。getDisplayHeight()获得设备的宽度和高度。您可以使用ADB获取像素密度:getprop ro.sf.lcd_density。然后使用公式px = dp *(dpi / 160),您可以生成公式dp = px /(dpi / 160)。最后,根据Android的屏幕尺寸指定如下:小-426dp x 320dp,普通-470dp x 320dp,大-640dp x 480dp和xlarge-960dp x 720dp,其中大尺寸和超大尺寸的尺寸为平板电脑:)。享受!
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);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句