After the launch of android 4, CalendarContract
class is introduce to write event in device calendar. But if i have created my app using API level 8 and Now i w
Find a way to find the api level programmatically... if you can then probably you can use appropriate code for diff Api levels... this may help Programmatically obtain the Android API level of a device?
You cannot use CalendarContract
on Android devices running less than API Level 14.
I managed to produce a work around to this problem today by piecing together different bits of advice found on SO and the wider web.
Basically I use a caretaker called CallendarAccess, and two classes with the same public method structure, one called CalendarLT14 in which the method calls resolve to the old undocumented way, and CalendarGTE14 which utilised the correct Android V14+way of doing things.
Both these classes extend a self written abstract class called CalendarService which contain abstract methods common to the public ones of CalendarLT14 and CalendarGTE14.
A problem in doing this is that Android versions less than IceCreamSandwich (v14) will not compile code such as CalendarContract callendarContact; which is written for later versions. To resolve this one sets the in the manifest the target version to 14 (Android 4.0), but the minimum version to 7 (android 2.1).This means the code 4.0 compiles and presents no problem to early versions because it is never invoked. Example method of the caretaker below.
public CalendarService getInstance()
{
if (Build.VERSION.SDK_INT >= 14)
return CalendarGTE14(context)
else
return CalendarLT14
}
This solution means the caretaker can selectively return an object which will resolve to the correct code relevant to the Android version in use and completely transparently to the programmer making calls to the caretaker or CalendarService class.