0

I my android app, i change the wallpaer/desktop image. How do i get the size of screen of the phone?

Note :I donot need the size of current activity but the screen.

Display display = getWindowManager().getDefaultDisplay();

int width = display.getWidth()
int height = display.getHeight()

Does the above code return the size of screen or current activity?Also display.getHeight() and display.getWidth methods are depreciated.

user93796
  • 18,749
  • 31
  • 94
  • 150

1 Answers1

1

Try

int screenHeight = (short) Activity.getWindow().getWindowManager().getDefaultDisplay().getHeight();
int screenWidth  = (short) Activity.getWindow().getWindowManager().getDefaultDisplay().getWidth();

source: Android | Getting screen height as width and screen width as height

Or to sum up @Parag Chauhan,

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

source:Get Screen width and height

Community
  • 1
  • 1
Asim Poptani
  • 158
  • 1
  • 14