Java make Android Calendar code sharing _java

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.