Simple code you only need context
DisplayMetrics metrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(metrics);
More info go to documentation
Or you can use this one
context.getResources().getDisplayMetrics()
but read documentation
Return the current display metrics that are in effect for this
resource object. The returned object should be treated as read-only.