Get and modify Android bring-your-own calendar schedule

Source: Internet
Author: User

the calendar in Android, only the real machine, the simulation is not, so the test environment must be real machine!!

Because the calendar is the system comes with, so we read and write it must apply permission, that is, in Androidmanifest.xml add the following two lines of code (one to read a write):

<!--get calendar read and Write permission--    <uses-permission android:name= "android.permission.READ_ CALENDAR "/>    <uses-permission android:name=" Android.permission.WRITE_CALENDAR "/>
Calendarthe schedule URL changes after the 2.2 version

In order to be compatible with different versions of the calendar, the URL changes after 2.2 The private static String Calandereventurl = ""; static {if (Integer.parseint (Build.VERSION.SDK) >= 8) {Calandereventurl = "content://com.android.calendar/events";} else {calandereventurl = "content://calendar/ Events ";}}
Here's the main code to get the schedule:
Contentresolver CR = Context.getcontentresolver ();//The Uriuri URI of the corresponding event in the calendar = Uri.parse (Calandereventurl); cursor cursor = cr.query (URI, NULL, NULL, NULL, NULL), while (Cursor.movetonext ()) {calendarevent CDE = new Calendarevent () ; cde.setcalendar_id (Cursor.getstring (Cursor.getcolumnindex (events.calendar_id))); Cde.settitle (cursor.getString (Cursor.getcolumnindex (Events.title))); Cde.setdtstart (Cursor.getstring (Cursor.getcolumnindex (Events.dtstart))) Cde.setdtend (Cursor.getString ( Cursor.getcolumnindex (Events.dtend)); Cde.setduration (Cursor.getstring (Cursor.getcolumnindex (Events.DURATION)) ); Cde.setrrule (Cursor.getstring (Cursor.getcolumnindex (Events.rrule)); Cde.seteventtimezone (Cursor.getString ( Cursor.getcolumnindex (Events.event_timezone)); Calendarevents.add (CDE);}
Here is the main code for writing the schedule

These fields are required for writing, so I've only written these fields.

Contentresolver CR = Context.getcontentresolver ();//The Uriuri URI of the corresponding event in the calendar = Uri.parse (Calandereventurl); cursor cursor = cr.query (URI, NULL, NULL, NULL, NULL), while (Cursor.movetonext ()) {calendarevent CDE = new Calendarevent () ; cde.setcalendar_id (Cursor.getstring (Cursor.getcolumnindex (events.calendar_id))); Cde.settitle (cursor.getString (Cursor.getcolumnindex (Events.title))); Cde.setdtstart (Cursor.getstring (Cursor.getcolumnindex (Events.dtstart))) Cde.setdtend (Cursor.getString ( Cursor.getcolumnindex (Events.dtend)); Cde.setduration (Cursor.getstring (Cursor.getcolumnindex (Events.DURATION)) ); Cde.setrrule (Cursor.getstring (Cursor.getcolumnindex (Events.rrule)); Cde.seteventtimezone (Cursor.getString ( Cursor.getcolumnindex (Events.event_timezone)); Calendarevents.add (CDE);}



Get and modify Android's own calendar schedule

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.