1
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?

Nifle
  • 11,745
  • 10
  • 75
  • 100
Sivaganesan.r
  • 261
  • 1
  • 5
  • 13
  • Display display = getWindowManager().getDefaultDisplay(); width = display.getWidth(); height = display.getHeight(); orientation=display.getOrientation(); i have used this code too but same problem exist ANY one please help me its very urgent for my application – Sivaganesan.r Jan 14 '11 at 12:51
  • Conclusion about how to get real resolution: http://stackoverflow.com/questions/11824193/htc-sensation-real-resolution – thecr0w Aug 09 '12 at 02:12

4 Answers4

3

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

Sivaganesan.r
  • 261
  • 1
  • 5
  • 13
0

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.

Nanne
  • 64,065
  • 16
  • 119
  • 163
0

try this

WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display d = wm.getDefaultDisplay();
int height = d.getHeight();
kamelot
  • 491
  • 1
  • 7
  • 19
  • Would that give a different value then the method he's using above? (just curious) – Nanne Jan 14 '11 at 13:08
  • @Nanne: I'm pretty sure that's the exact same thing as the original method, just a different method of acquiring the WindowManager. – Kevin Coppock Jan 14 '11 at 13:21
0

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.

Matt
  • 3,837
  • 26
  • 29