0

does anyone know how to add event to usercreated calender in android.. i am created calender then i just want to add event to this calender i don't know to add event to this calender.....plz help

this mainactivity define it return uri of created calender. calender successfully created but how to use and how to add event to calender

      public class MainActivity extends AppCompatActivity
        {


            String Eventmanagement="eventmanagement";
            String accountName="com.google";
            protected Uri baseUri = Uri.parse("content://com.android.calendar/calendars");
            protected void onCreate(Bundle savedInstanceState)
            {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                //Uri uri=createCalendarWithName(MainActivity.this,Eventmanagement,accountName);
                //System.out.println(uri);
            }



            public  Uri createCalendarWithName(Context ctx, String name,String accountName) {

                Uri target = createCompleteUri();
        //        target = target.buildUpon().appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
        //                .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, accountName)
        //                .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, "com.google").build();
                ContentValues values = new ContentValues();
                values.put(CalendarContract.Calendars.ACCOUNT_NAME, accountName);
                values.put(CalendarContract.Calendars._ID,11);
                values.put(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
                values.put(CalendarContract.Calendars.NAME, name);
                values.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, name);
                values.put(CalendarContract.Calendars.CALENDAR_COLOR, 0x00FF00);
                values.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_ROOT);
                values.put(CalendarContract.Calendars.OWNER_ACCOUNT, accountName);
                values.put(CalendarContract.Calendars.VISIBLE, 1);
                values.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
                values.put(CalendarContract.Calendars.CALENDAR_TIME_ZONE, "Europe/Rome");
                values.put(CalendarContract.Calendars.CAN_PARTIALLY_UPDATE, 1);
               // values.put(CalendarContract.Calendars.CAL_SYNC1, "https://www.google.com/calendar/feeds/" + accountName + "/private/full");
              //  values.put(CalendarContract.Calendars.CAL_SYNC2, "https://www.google.com/calendar/feeds/default/allcalendars/full/" + accountName);
              //  values.put(CalendarContract.Calendars.CAL_SYNC3, "https://www.google.com/calendar/feeds/default/allcalendars/full/" + accountName);
               // values.put(CalendarContract.Calendars.CAL_SYNC4, 1);
               // values.put(CalendarContract.Calendars.CAL_SYNC5, 0);
              //  values.put(CalendarContract.Calendars.CAL_SYNC8, System.currentTimeMillis());

                Uri newCalendar = ctx.getContentResolver().insert(target, values);
        System.out.println("created succesfully");
                return newCalendar;
            }
            private  Uri createCompleteUri()
            {
                Uri.Builder b =baseUri.buildUpon();
                b.appendQueryParameter("caller_is_syncadapter", "true");
                b.appendQueryParameter("account_name", "local");
                b.appendQueryParameter("account_type", "LOCAL");
                Uri calUri = b.build();
                Log.d("completeUri", calUri.toString());
                return calUri;
            }



        }
1
  • plz anyone know about this.....i'm creating calender but how to access i dont know plz...suggest me how to do.........
    – sumit
    Commented Mar 31, 2016 at 10:05

1 Answer 1

0

1.Check the documentation

2.And then see the tutorial

...

long calId = getCalendarId();
if (calId == -1) {
   // no calendar account; react meaningfully
   return;
}
Calendar cal = new GregorianCalendar(2012, 11, 14);
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
long start = cal.getTimeInMillis();
ContentValues values = new ContentValues();
values.put(Events.DTSTART, start);
values.put(Events.DTEND, start);
values.put(Events.RRULE,
      "FREQ=DAILY;COUNT=20;BYDAY=MO,TU,WE,TH,FR;WKST=MO");
values.put(Events.TITLE, "Some title");
values.put(Events.EVENT_LOCATION, "Münster");
values.put(Events.CALENDAR_ID, calId);
values.put(Events.EVENT_TIMEZONE, "Europe/Berlin");
values.put(Events.DESCRIPTION,
      "The agenda or some description of the event");
// reasonable defaults exist:
values.put(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
values.put(Events.SELF_ATTENDEE_STATUS,
      Events.STATUS_CONFIRMED);
values.put(Events.ALL_DAY, 1);
values.put(Events.ORGANIZER, "[email protected]");
values.put(Events.GUESTS_CAN_INVITE_OTHERS, 1);
values.put(Events.GUESTS_CAN_MODIFY, 1);
values.put(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
Uri uri =
      getContentResolver().
            insert(Events.CONTENT_URI, values);
long eventId = new Long(uri.getLastPathSegment());
...
2
  • but how to display that calender with event on ui page means how map calenderview and it......
    – sumit
    Commented Mar 31, 2016 at 11:15
  • hey bro i created calender and get calender id....but how to map calenderview and its created calender.....means how to add events and show on calenderview.....plz suggest sorry i'm new in android
    – sumit
    Commented Mar 31, 2016 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.