На Android существует метод, более мощный, чем t он ссылается на схемы. Намерения И это действительно действительно более мощный!
Вы можете открыть календарь или добавить событие календаря с (и намерениями много других применений, такими как открытый щебет, разделяет изображение на WhatsApp, создать заметку о Evernote ...)
В this link вы может найти решение. Будьте осторожны с android < 4.0, потому что api календаря изменяется и стандартизируется на Android 4.0. Read this this post too
Для добавления события календаря Вы следуете следующий код: (это пример, может быть, вы не используете все это или, возможно, ваш формат даты отличается)
/**
* Creates a calendar event
*
* @param ce calendar event information
* @return
*/
protected static boolean createCalendarEvent(Context context, CalendarEventCustomObject ce) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
return createCalendarEventIceCream(context, ce);
else
return createCalendarEventNormal(context, ce);
}
@SuppressLint("SimpleDateFormat")
protected static boolean createCalendarEventNormal(Context context, CalendarEventCustomObject ce) {
try {
Intent calIntent = new Intent(Intent.ACTION_EDIT);
calIntent.setType("vnd.android.cursor.item/event");
calIntent.putExtra("title", ce.description);
calIntent.putExtra("eventLocation", ce.location);
calIntent.putExtra("description", ce.summary);
calIntent.putExtra("calendar_id", ce.id);
// Add date info
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
Long start = Utils.parseDate(ce.start, df);
if (start == null) {
start = Utils.parseDate(ce.start, df2);
if (start == null)
start = System.currentTimeMillis();
}
Long end = Utils.parseDate(ce.end, df);
if (end == null) {
end = Utils.parseDate(ce.end, df2);
if (end == null)
end = System.currentTimeMillis();
}
calIntent.putExtra("beginTime", start);
calIntent.putExtra("endTime", end);
context.startActivity(calIntent);
return true;
} catch (Exception e) {
return false;
}
}
@SuppressLint("NewApi")
protected static boolean createCalendarEventIceCream(Context context, CalendarEventCustomObject ce) {
try {
Intent calIntent = new Intent(Intent.ACTION_INSERT);
calIntent.setType("vnd.android.cursor.item/event");
// Create intent and add string info
calIntent.putExtra(Events.TITLE, ce.description);
calIntent.putExtra(Events.EVENT_LOCATION, ce.location);
calIntent.putExtra(Events.DESCRIPTION, ce.summary);
calIntent.putExtra(Events.CALENDAR_ID, ce.id);
// add date info
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
Long start = Utils.parseDate(ce.start, df);
if (start == null) {
start = Utils.parseDate(ce.start, df2);
if (start == null)
start = System.currentTimeMillis();
}
Long end = Utils.parseDate(ce.end, df);
if (end == null) {
end = Utils.parseDate(ce.end, df2);
if (end == null)
end = System.currentTimeMillis();
}
calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start);
calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end);
calIntent.setData(CalendarContract.Events.CONTENT_URI);
((Activity) context).startActivity(calIntent);
return true;
} catch (Exception e) {
return false;
}
}
ли вы найти путь? – Robert