How to detect the screen size for different android phones?

I want the coordinate values like startx, starty, endx, endy. With that I can use the swipe method which takes these coordinates as parameters.

I used
Dimension size = driver.manage().window().getSize();

2 Answers 2


You can get the screen width and screen height using the below code:

  Dimension dimensions = driver.manage().window().getSize();
  int screenWidth = dimensions.getWidth();
  int screenHeight = dimensions.getHeight();

There are a few methods to do this,

  1. getSize() methods

    Display screensize = getWindowManager().getDefaultDisplay(); Point size = new Point(); screensize.getSize(size); int width = size.x; int height = size.y;

  2. Ge default display size:

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display screensize = wm.getDefaultDisplay();

  3. getWidth() and getHeight() methods

    Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); // deprecated int height = display.getHeight(); // deprecated

  4. DisplayMetrics() method:

    DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int height = displaymetrics.heightPixels; int width = displaymetrics.widthPixels;

Hope this helps you! :)

Not the answer you're looking for? Browse other questions tagged or ask your own question.