The code is simple, no more nonsense.
Copy Code code as follows:
Reading Calendar Events
public static void Getcalendarinfo (activity activity,string tag) {
string[] projection = new String[]{calendarcontract.events._id,calendarcontract.events.title};
Contentresolver CR = Activity.getcontentresolver ();
Cursor Cursor = cr.query (CalendarContract.Events.CONTENT_URI, projection, NULL, NULL, NULL);
int idindex = Cursor.getcolumnindexorthrow (calendarcontract.events._id);
LOG.D (tag, cursor.getcount () + "");
int titleindex = Cursor.getcolumnindexorthrow (CalendarContract.Events.TITLE);
while (Cursor.movetonext ()) {
String id = cursor.getstring (idindex);
String title = cursor.getstring (Titleindex);
LOG.D (Tag, id+ ":" +title);
}
Cursor.close ();
}
Insert Event
public static void Addcalendarevent (activity activity,string tag) {
Intent Intent = new Intent (Intent.action_insert,calendarcontract.events.content_uri);
LOG.D (tag, CalendarContract.Events.CONTENT_URI.toString ());
Intent.putextra (CalendarContract.Events.TITLE, "Launch");
Intent.putextra (CalendarContract.Events.DESCRIPTION, "launch,android app");
Intent.putextra (CalendarContract.Events.EVENT_LOCATION, "baidu.com");
Calendar calendar = Calendar.getinstance ();
Calendar.settime (New Date ());
Intent.putextra (Calendarcontract.extra_event_begin_time, Calendar.gettimeinmillis ());
Intent.putextra (Calendarcontract.extra_event_all_day, true);
Activity.startactivity (Intent);
}
Edit Calendar Events
public static void Editcalendarevent (activity activity,string tag) {
Long rowId = 1;
Uri Edituri = Contenturis.withappendedid (Calendarcontract.events.content_uri,rowid);
LOG.D (tag, CalendarContract.Events.CONTENT_URI.toString ());
Intent Intent = new Intent (Intent.action_edit,edituri);
Intent.putextra (CalendarContract.Events.EVENT_LOCATION, "NJ");
Calendar calendar = Calendar.getinstance ();
Calendar.set (2015, 2, 17, 12, 1, 1);
Intent.putextra (Calendarcontract.extra_event_begin_time, Calendar.gettimeinmillis ());
Intent.putextra (Calendarcontract.extra_event_all_day, true);
Activity.startactivity (Intent);
}
View Calendar
public static void Viewcalendar (activity activity,string tag) {
Calendar calendar = Calendar.getinstance ();
Calendar.set (2015, 2, 17, 12, 1, 1);
Uri uri = uri.parse ("content://com.android.calendar/time/" +calendar.gettimeinmillis ());
Intent Intent = new Intent (Intent.action_view,uri);
Activity.startactivity (Intent);
}
The above is the article to share all the code, I hope to learn Java can help.