Sivaganesan.r
Sivaganesan.r

Reputation: 261

android problem in getting the screen resolution size

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
height = displaymetrics.heightPixels;
width = displaymetrics.widthPixels;
Log.e("FirstImage", "Width = "+width+"Height = "+height);

The above was the code I have used to display the screen size.. but the problem is I am getting width=320 and height=569. But I am using motorola milestone with screen size 480x854

How can I get the correct size?

Upvotes: 1

Views: 5020

Answers (4)

Sivaganesan.r
Sivaganesan.r

Reputation: 261

http://realmike.org/blog/2010/12/21/multiple-screen-sizes-with-processing-for-android/

above link has excellent resource that tells about the screen resolution and how to get the real screen resolution etc....read fully you will come to know about the reality

Upvotes: 3

Matt
Matt

Reputation: 3847

The <supports-screens> tag should definitely work. See

http://developer.android.com/guide/topics/manifest/supports-screens-element.html

An important question is, why don't you trust the scaled dimensions you're getting from the DisplayMetrics? If you were to do something like

canvas.drawRect(new Rect(0,0,width,height), new Paint());

Your rectangle would certainly fill the screen. There's a scaling happening, but maybe you don't care.

Upvotes: 0

kamelot
kamelot

Reputation: 491

try this

WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display d = wm.getDefaultDisplay();
int height = d.getHeight();

Upvotes: 0

Nanne
Nanne

Reputation: 64399

If you don't set the supporting of larger screens, you'll get this i'm afraid, because the screen is pretending to be smaller to be able to show the app (that is supposed to not support your big screen).

If you add this to your manifest it will show the correct values

     <supports-screens 
        android:largeScreens="true" 
        android:smallScreens="true" 
        android:normalScreens="true" 
     /> 

you might even want to play with the

 android:anyDensity

attribute, but I don't think it is needed for your current problem.

Upvotes: 0

Related Questions