Is it possble to target Android 2.1 and use CalendarProvider on devices with Android 4.0 and higher or is it can only be achieved by creating 2 separate APKs?
Is it possble to target Android 2.1 and use CalendarProvider on devices with Android
Share
That depends on what you mean by “target”.
If you mean “set targetSdkVersion” to Android 2.1, you can still use whatever APIs you want, so long as you only try calling them when you are running on a device that has them.
If you mean “set the build target” to Android 2.1, you can still use whatever APIs you want, so long as you use reflection to access the ones that are newer than API Level 7. Since
CalendarContractis a content provider, that mostly is a matter of accessing various static data members, such asCONTENT_URI. Here is an example of using reflection to get at aCONTENT_URIvalue:(note: this example is designed to run on Android 1.5 and higher — depending on your
minSdkVersion, you could useBuild.VERSION.SDK_INTinstead ofnew Integer(Build.VERSION.SDK).intValue()).If by “target” you mean something else, then we would need clarification of your use of the verb “target”.