Question

I'm trying to support Devices with API level 10 onwards. To check the screen size I have this:

Point size = new Point();
Display display = getWindowManager().getDefaultDisplay();
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
    size.set(display.getWidth(), display.getHeight());
} else
    getWindowManager().getDefaultDisplay().getSize(size);

But now I recieve an error because I use getSize() even though my min level is 10.
How to properly do that?

edit: In the app's manifest file I have:

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="15" />
Was it helpful?

Solution

You can keep your minimum SDK level set to 10 but build your Android app against Android 3.2 (or even higher if you'd like, set it in the project properties).

Just make sure that if you call methods from a higher api level than you minimum level, then first check the device SDK level like you did.

More about it here:

http://simonvt.net/2012/02/07/what-api-level-should-i-target/

Also use TargetApi annotations to avoid Lint errors:

http://tools.android.com/recent/lintapicheck

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top