How to get screen resolution of an android device using LIBGDX?-ThrowExceptions

Exception or error:

I am working android game development and I am new in it.
I want to develop a game which screen resolution free. It will be enough for me if i get to know that how to catch screen resolution of an android device using libgdx library.
After some googling i read the following code on different sites, but it is not for libgdx.

DisplayMetrics displaymetrics = new DisplayMetrics();
height = displaymetrics.heightPixels;
width = displaymetrics.widthPixels;

Except this i also used technique given on the following website that used “OrthographicCamera” class for solving the problem, and didn’t work for me either.

How can i get the screen resolution or any way to adjust screen resolution for my game.

How to solve:;;



ok you can get the screen resolution by this;

//for screen width;

//for screen height

and if you want to make a screen resolution free game you can set the view port like this

float scrw=320;

float scrh=480;

scrw is viewport’s width and scrh is viewport’s height

and set the camera to

camera = new OrthographicCamera();
camera.setToOrtho(false, scrw, scrh);


Though there are some answers here on my question. This is what exactly worked for me. I had to add ‘app’ after ‘Gdx’ for it to work.;;


In the newer LibGDX release, the code is now

int width =;
int height =;


int width =;
int height =;

works for me.

Leave a Reply

Your email address will not be published. Required fields are marked *