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;
}
}