I'm building an App for Android, but I'd like to make it so I can use 4.0.3 features as a minimum. I'm not worried currently about releasing this for those who use 4.0 and below.
Basically, my questions are as follows:
If I already have a project with a base minimum SDK in Eclipse set to 4.0.3, with the max set to the same, can I change the maximum? If so, how?
Are 4.0.3 apps compatible with 4.1 apps at all? If not, what's a good work around for this? If I were doing this in C/C++ the answer would be a preprocessor directive (e.g., #ifdef ANDROID_OS_4_1 //do stuff for 4.1 only #endif
). I know of no such equivalent in Java, however, let alone for Android.
To build against JellyBean, you can use the <uses-sdk />
tag in your AndroidManifest (just above your <application />
tag):
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="16"/>
By using a targetSdkVersion of 16 (JellyBean) you get access to all the new API's
At runtime you can then check what version of Android the app is running on and perform actions based off that. I use a utility class in my apps to do this:
public class Api {
public static final int LEVEL = Build.VERSION.SDK_INT;
public static final int FROYO = Build.VERSION_CODES.FROYO;
public static final int GINGERBREAD = Build.VERSION_CODES.GINGERBREAD;
public static final int GINGERBREAD_MR1 = Build.VERSION_CODES.GINGERBREAD_MR1;
public static final int HONEYCOMB = Build.VERSION_CODES.HONEYCOMB;
public static final int ICS = Build.VERSION_CODES.ICE_CREAM_SANDWICH;
public static final int JELLYBEAN = Build.VERSION_CODES.JELLY_BEAN;
public static boolean isMin(int level) {
return LEVEL >= level;
}
}
Then in your code you can do things like:
if(Api.isMin(Api.JELLYBEAN) )
doJellybeanStuff();
else if(Api.isMin(Api.ICS) )
doIcsStuff();
else
doOldStuff();