如何在不使用intent的情况下向android日历添加事件和提醒
我已经尝试了很多来自堆栈溢出的代码,但我能够添加事件和提醒。我是android开发的新手。请帮帮我 下面是找到的用于堆栈溢出的代码如何在不使用intent的情况下向android日历添加事件和提醒,android,calendar,Android,Calendar,我已经尝试了很多来自堆栈溢出的代码,但我能够添加事件和提醒。我是android开发的新手。请帮帮我 下面是找到的用于堆栈溢出的代码 ContentValues cv = new ContentValues(); ContentResolver cr = getContentResolver(); Calendar cal = Calendar.getInstance(); cv.put("calendar_id", 1); cv.put("ti
ContentValues cv = new ContentValues();
ContentResolver cr = getContentResolver();
Calendar cal = Calendar.getInstance();
cv.put("calendar_id", 1);
cv.put("title", "Prog");
cv.put("dtstart", cal.getTimeInMillis() );
cv.put("hasAlarm", 1);
cv.put("dtend", cal.getTimeInMillis()+1000*60*60);
cv.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
Uri newEvent ;
if (Integer.parseInt(Build.VERSION.SDK) >= 8 ){
newEvent = cr.insert(Uri.parse("content://com.android.calendar/events"), cv);
}
else{
newEvent = cr.insert(Uri.parse("content://calendar/events"), cv);
}
if (newEvent != null)
{
long id = Long.parseLong( newEvent.getLastPathSegment() );
ContentValues values = new ContentValues();
values.put( "event_id", id );
values.put( "method", 1 );
values.put( "minutes", 0 ); // 15 minut Before
values.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
if (Integer.parseInt(Build.VERSION.SDK) >= 8 )
cr.insert( Uri.parse( "content://com.android.calendar/reminders" ), values );
else
cr.insert( Uri.parse( "content://calendar/reminders" ), values );
}