Это мой личный класс CalendarOrganizer, они изменили способ доступа к календарю из сэндвича с мороженым, на самом деле перед сэндвичем с мороженым рекомендуется использовать их онлайн-сервисы для обновления календаря, поскольку календарь Google может быть изменен или даже не установлен.
Правка. Я узнал, что мне нужно решать проблемы с намерением, но также и то, что некоторые телефоны на бутерброде с мороженым будут аварийно завершать работу из-за Intent.ACTION_INSERT, но не из-за Intent.ACTION_EDIT. Поэтому я обновил свою реализацию. Спасибо этому сообщению за решение.
import android.content.Context;
import android.content.Intent;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Events;
public class CalendarOrganizer {
private final static int ICE_CREAM_BUILD_ID = 14;
/**
* Creates a calendar intent going from startTime to endTime
* @param startTime
* @param endTime
* @param context
* @return true if the intent can be handled and was started,
* false if the intent can't be handled
*/
public static boolean createEvent(long startTime, long endTime, String title, String description,
String location, boolean isAllDay, Context context) {
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < ICE_CREAM_BUILD_ID) {
// all SDK below ice cream sandwich
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", startTime);
intent.putExtra("endTime", endTime);
intent.putExtra("title", title);
intent.putExtra("description", description);
intent.putExtra("eventLocation", location);
intent.putExtra("allDay", isAllDay);
// intent.putExtra("rrule", "FREQ=YEARLY");
try {
context.startActivity(intent);
return true;
} catch(Exception e) {
return false;
}
} else {
// ice cream sandwich and above
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startTime);
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime);
intent.putExtra(Events.TITLE, title);
intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY , isAllDay);
intent.putExtra(Events.DESCRIPTION, description);
intent.putExtra(Events.EVENT_LOCATION, location);
// intent.putExtra(Events.RRULE, "FREQ=DAILY;COUNT=10")
try {
context.startActivity(intent);
return true;
} catch(Exception e) {
return false;
}
}
}
}
person
Warpzit
schedule
13.06.2012