Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...