6
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);

    int w = displaymetrics.widthPixels;
    int h = displaymetrics.heightPixels;

I'm using a "Nexus One"

W shoud be 480 and H shoud be 800 ...

But for me W is 320 and H is 533...

What am I doing wrong???

        DisplayMetrics displayMetrics = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

    float CAMERA_WIDTH = displayMetrics.widthPixels
            * getResources().getDisplayMetrics().density;
    ;
    float CAMERA_HEIGHT = displayMetrics.heightPixels
            * getResources().getDisplayMetrics().density;
    ;

    Log.v("" + CAMERA_WIDTH + "---"
            + CAMERA_HEIGHT);

VERBOSE: 320.0---533.0

Karl
  • 149
  • 1
  • 7

2 Answers2

7

Needs a

    <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="10" />
Karl
  • 149
  • 1
  • 7
2

Karl, you have to take the screen density into account. You will need to multiply each of those values by...

density = getResources().getDisplayMetrics().density;
int w = displaymetrics.widthPixels * density;
int h = displaymetrics.heightPixels * density;

That will give you the actual screen size

Will Tate
  • 33,439
  • 9
  • 77
  • 71