Sometimes you want to know the screen width and height in pixels. An example can be that you are developing a system information app and you have to display screen width and height in your activity. This is going to be so simple with very few lines of code. The following code snippet give you the screen width and height in pixels.
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
int width = size.x;
int height = size.y;
Log.e("Width", "" + width);
Log.e("height", "" + height);
Enjoy Coding and Share Knowledge