Skip to content

Commit e84cabe

Browse files
author
videopls
committed
VenvyUIUtil.java实现屏幕密度的获取
1 parent 269cefb commit e84cabe

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

VideoOS/VenvyLibrary/src/main/java/cn/com/venvy/common/utils/VenvyUIUtil.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,14 @@ public static int getScreenWidth(@Nullable Context context) {
655655
}
656656

657657
public static int getScreenPPI(@Nullable Context context) {
658-
DisplayMetrics dm = new DisplayMetrics();
659-
return dm.densityDpi;
658+
WindowManager windowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
659+
DisplayMetrics displayMetrics = new DisplayMetrics();
660+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
661+
windowManager.getDefaultDisplay().getRealMetrics(displayMetrics);
662+
}else{
663+
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
664+
}
665+
return displayMetrics.densityDpi;
660666
}
661667

662668
/**

0 commit comments

Comments
 (0)