我的一位用户获得的每英寸像素值为0.288。 (getPixelsperInch = 0.288)
我使用以下代码来确定pixelperinche。 我在这里做错了什么?
他的Screensize是976/600。 使用我自己的设备,我得到合理的价值。 有问题的设备是" UTOK700Q"。
public float getPixelsperInch() {
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
float fpixelperinch = dm.xdpi;
return fpixelperinch;
}
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int iScreenHeight = metrics.heightPixels;
int iScreenWidth = metrics.widthPixels;
答案 0 :(得分:1)
这样做....
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
// density interms of dpi
Log.i(TAG, "D density :" + metrics.densityDpi);
答案 1 :(得分:0)
愿这对你有帮助......
WindowManager windowManager = getWindowManager();
Display display = windowManager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
// since SDK_INT = 1;
mWidthPixels = displayMetrics.widthPixels;
mHeightPixels = displayMetrics.heightPixels;
// includes window decorations (statusbar bar/menu bar)
if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17) {
try {
mWidthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
mHeightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
} catch (Exception ignored) {
}
}
// includes window decorations (statusbar bar/menu bar)
if (Build.VERSION.SDK_INT >= 17) {
try {
Point realSize = new Point();
Display.class.getMethod("getRealSize", Point.class).invoke(display, realSize);
mWidthPixels = realSize.x;
mHeightPixels = realSize.y;
} catch (Exception ignored) {
}
}
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
double x = Math.pow(mWidthPixels / dm.xdpi, 2);
double y = Math.pow(mHeightPixels / dm.ydpi, 2);
double screenInches = Math.sqrt(x + y);
Log.d("debug", "Screen inches : " + screenInches);