Вопрос

My application needs the functionality to add Events into internal phone Caledar. In API 14 it is possible via CalendarContract with smth like the code below. What would be an alternative in API 8? Or is it possible to detect the API in code and depending on the version turn this on/off?

    Intent intent = new Intent(Intent.ACTION_INSERT);
    intent.setType("vnd.android.cursor.item/event");
    intent.putExtra(Events.TITLE, "Learn Android");
    intent.putExtra(Events.EVENT_LOCATION, "Home suit home");
    intent.putExtra(Events.DESCRIPTION, "Download Examples");

    // Setting dates
    GregorianCalendar calDate = new GregorianCalendar(2012, 10, 02);
    intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
      calDate.getTimeInMillis());
    intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
      calDate.getTimeInMillis());

    // Make it a full day event
    intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);

    // Make it a recurring Event
    intent.putExtra(Events.RRULE, "FREQ=WEEKLY;COUNT=11;WKST=SU;BYDAY=TU,TH");

    // Making it private and shown as busy
    intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
    intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
    startActivity(intent); 
Это было полезно?

Решение

As you said that is only available on API 14 and there's no alternative on API 8. The best you could do in the past was to directly access the web-api for the google calendars.

So in general the best approach is to use the SDK_INT to see what's the API version and enable/disable the feature as needed.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top