Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Showing wrong screen resolution

I was trying to get the screen resolution of android phones,using this code

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    str_ScreenSize = dm.widthPixels + " x " + dm.heightPixels;
    str_ScreenSize = "dd" + " x " + dm.heightPixels;

When i tried this code in my Galaxy S phone i got the screen resolution as 320x533 px, but in reality the Galaxy S got a screen resolution of 480x800 px. So what's wrong with the code??

How can i get the actual screen resolution of a particular device??

like image 971
Shijilal Avatar asked Feb 22 '11 13:02

Shijilal


People also ask

How do I fix wrong screen resolution?

Click Start, and then click Control Panel. In the Control Panel window, click Appearance and Themes, and then click Display. In the Display Properties window, click the Settings tab. Under Screen resolution, click and drag the horizontal slider control to change the screen resolution, and then click Apply.


1 Answers

Finally after 2 days of searching and testing, i finally managed to find out what's the real issue here.. All those above coding will give correct resolution. But the most important this is that we need to mention the target SDK in the manifest file.. Otherwise it will give wrong result if the density is more than 1.

<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" />

need to set the targetSDK version from anything between 4-9.. Hope this will help some one in future facing the same issue.

like image 121
Shijilal Avatar answered Sep 29 '22 05:09

Shijilal