I know this kind of question has been asked before, for example here: Android: how to code depending on the version of the API?
There it is also mentioned that one has to compile to the newest Android level. My basic app version should be available with 7 and the more advanced starting with level 12.
So does that mean that the target setting of the project should be 12 as well as the min-sdk in the manifest.
BUT the app in the Android market will then ONLY be available to level 12 devices? Even though the app should run starting with 7 - just with limited features.
Also in level 12 I would need to import certain packages only available starting at 12. So I could not even set a lower Android target, otherwise I get compiler error.
So in summary:
Many thanks!
If I'm reading your question correctly then this would allow you application to be installed on devices with level 7
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="12" />
For development you can set it to any target you want i.e. your project target can be SDK 4.0 but you manifest target can be 1.5 (android:targetSdkVersion="3") or vice versa. Eclipse will give you a warning but you can develop for any target and set you manifest to any target as long as you take in to account the consequences.
You are probably aware there is a bit of work to do in you code to make sure the application doesn't crash if it tries to call methods that don't exist at level 7. I have written code to handle that if you want some examples.
EDIT:
An example that works for me.
/**
* Get the current SDK version as an integer. If we are using 1.5 the SDK is
* returned as a String so using the Build.VERSION.SDK_INT method will cause
* the application to crash. This method will return 3 if the version is 1.5
* and will return the proper result for Build.VERSION.SDK_INT if that
* method is available.
*
* @return
*/
public static int getSdkInt() {
if (Build.VERSION.RELEASE.startsWith("1.5"))
return 3;
try {
return YourInternalClass.getSdkIntInternal();
} catch (VerifyError e) {
Log.e(TAG, e.toString());
return 3;
}
}
You should call any methods that may not exist in an internal class so it wont load up until the method is called.
private static class YourInternalClass {
private static int getSdkIntInternal() {
return Build.VERSION.SDK_INT;
}
}
Now you can check the SDK version. If you have any methods that exist only in packages greater than 7, put those methods in an internal class. then you can do
if(TheClassYouPutThisMethodIn.getSDKInt() >= 12)
YourInternalClass.yourLevel12Method();
I'm sure there is probably a better way to do this (and I hope someone could post it) but it works great for me. I have applications that use methods from SDK 13 running safely on phone with level 3.
Hope this helps.