• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps how to get screen width and height for every api level

hi there
by using this code i want to get screen height and width for every api level.
Java:
        if(android.os.Build.VERSION.SDK_INT < 13){
            screenWidth = getWindowManager().getDefaultDisplay().getWidth();
            screenHeight = getWindowManager().getDefaultDisplay().getHeight();
        }else
        {
            Point p = new Point();
            getWindowManager().getDefaultDisplay().getSize(p);
            screenWidth = p.x;
            screenHeight = p.y;
        }

problem is that i have this in my manifest:
Code:
<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

and this line of code :
Java:
getWindowManager().getDefaultDisplay().getSize(p);

gimme following error:
Call requires API level 13 (current min is 8): android.view.Display#getSize
 
I use that kind of code and I only get a warning in Eclipse, not error, so it still works to compile.

Are you sure it doesn't work?
 
Like @Manaya stated... it should only be a warning. You can get rid of that warning by adding:

Java:
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
@SuppressWarnings("deprecation")

That placed right above your function.
 
no, i tested again and got that error, tried to run without mentioning it but following happened :
Your project contain error(s), please fix them before running your application.

and is for this manifest setting :
Code:
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />
 
Back
Top Bottom