Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate new synced calendar with android api
    primarykey
    data
    text
    <p>i'm trying to create a calendar on my account to fill with events that i get from some websites. I've searched and found some new android 4.0 calendar example that i've modified to obtain what i need. The problem is that the calendar is created, filled with events but not synced with google calendar, so in the next sync it is erased. The funcion i use are these:</p> <p>This is the one for add the new calendar if don't alreay exist:</p> <pre><code>public static Uri createCalendarWithName(Context ctx, String name,String accountName) { Uri target = Uri.parse(CalendarContract.Calendars.CONTENT_URI.toString()); 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(Calendars.ACCOUNT_NAME, accountName); values.put(Calendars.ACCOUNT_TYPE, "com.google"); values.put(Calendars.NAME, name); values.put(Calendars.CALENDAR_DISPLAY_NAME, name); values.put(Calendars.CALENDAR_COLOR, 0x00FF00); values.put(Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_ROOT); values.put(Calendars.OWNER_ACCOUNT, accountName); values.put(Calendars.VISIBLE, 1); values.put(Calendars.SYNC_EVENTS, 1); values.put(Calendars.CALENDAR_TIME_ZONE, "Europe/Rome"); values.put(Calendars.CAN_PARTIALLY_UPDATE, 1); values.put(Calendars.CAL_SYNC1, "https://www.google.com/calendar/feeds/" + accountName + "/private/full"); values.put(Calendars.CAL_SYNC2, "https://www.google.com/calendar/feeds/default/allcalendars/full/" + accountName); values.put(Calendars.CAL_SYNC3, "https://www.google.com/calendar/feeds/default/allcalendars/full/" + accountName); values.put(Calendars.CAL_SYNC4, 1); values.put(Calendars.CAL_SYNC5, 0); values.put(Calendars.CAL_SYNC8, System.currentTimeMillis()); Uri newCalendar = ctx.getContentResolver().insert(target, values); return newCalendar; } </code></pre> <p>and that one create the new event without interaction:</p> <pre><code>public static Uri createEventWithName(Context ctx, long id, String name, String data) { long startMillis = 0; long endMillis = 0; int id2=(int)id; String[] divisi = data.split("/"); Calendar beginTime = Calendar.getInstance(); beginTime.set(2012,Integer.parseInt(divisi[0])-1, Integer.parseInt(divisi[1])); startMillis = beginTime.getTimeInMillis(); Calendar endTime = Calendar.getInstance(); endTime.set(2012,Integer.parseInt(divisi[0])-1, Integer.parseInt(divisi[1])); endMillis = endTime.getTimeInMillis(); ContentValues cv = new ContentValues(); cv.put(Events.TITLE, name); cv.put(Events.DTSTART, startMillis); cv.put(Events.DTEND, endMillis); cv.put(Events.CALENDAR_ID, id2); Log.d("aggiungo a calendario",Integer.toString(id2)); cv.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().toString()); //cv.put(Events.RRULE, "FREQ=DAILY;INTERVAL=2"); Uri newEvent = ctx.getContentResolver().insert(CalendarContract.Events.CONTENT_URI, cv); return newEvent; } </code></pre> <p>I'm not so experienced in Android programming so i think it's a stupid question =) i've read that accountName and Account Type must be the same that the one stored on android device, else the event is cancelled. I get accountName from android api and i think they are correct. The account type seems to work for other....</p> <p>Thanks to anybody that help me!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload