3

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();

closed as off-topic by Niels van Reijmersdal, IAmMilinPatel, demouser123, Kate Paulk, Bruce McLeod Feb 11 '16 at 10:20

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development unrelated to testing are off-topic here, but can be asked on Stack Overflow." – Niels van Reijmersdal, IAmMilinPatel, demouser123, Kate Paulk, Bruce McLeod
If this question can be reworded to fit the rules in the help center, please edit the question.

1

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();
0

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! :)

TESTasy

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