How to get width and height(in pixels) of an android device programatically

Getting width 


@SuppressLint("NewApi")
public int getDeviceWidth()
{
 int deviceWidth = 0;

 Point size = new Point();
 WindowManager windowManager = getWindowManager();

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
 {
 windowManager.getDefaultDisplay().getSize(size);
 deviceWidth = size.x;
 }
 else
 {
 Display display = windowManager.getDefaultDisplay();
 deviceWidth = display.getWidth();
 }
 return deviceWidth;
}

Getting height 


@SuppressLint("NewApi")
public int getDeviceHeight()
{
 int deviceHeight = 0;

 Point size = new Point();
 WindowManager windowManager = getWindowManager();

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
 {
 windowManager.getDefaultDisplay().getSize(size);
 deviceHeight = size.y;
 }
 else
 {
 Display display = windowManager.getDefaultDisplay();
 deviceHeight = display.getHeight();
 }
 return deviceHeight;
}

Advertisements

Tags: ,

About krishjlk

http://www.facebook.com/krishna.kanth.121

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: