Cannot fetch ExtendedProperties, existing in an event Android calendar - android

Synchronisation is made between Android calendar and my Exchange account,
initially i have created event from Outlook with extended properties, then when i'm fetching those extended properties in Android calendar using the snippet below:
cursorExtendedProp = context.getContentResolver().query(Uri.parse(ExtendedProperties.CONTENT_URI.toString()),new String[] {ExtendedProperties._ID, ExtendedProperties.NAME, ExtendedProperties.VALUE}, null, null, null);
while (cursorExtendedProp.moveToNext()) {
cursorExtendedProp.getString(0);
cursorExtendedProp.getString(1);
cursorExtendedProp.getString(2);
}
cursorExtendedProp.close();
I didn't not get the extended propreties created initially from outlook.
did i miss something ? need some help.

Related

Android Calendar Provider: Only initially created extended property syncs across devices, all further updates do not sync

When I create a Google Calendar event and attach extended property to it, all is working as expected - both event and its extended property get synced so they can be accessed from different devices. Here is the code:
// create event with extended property
ContentValues values = new ContentValues();
...
values.put(CalendarContract.Events.HAS_EXTENDED_PROPERTIES, 1);
Uri eventURI = contentResolver.insert(CalendarContract.Events.CONTENT_URI, values);
long eventID = Long.parseLong(eventURI.getLastPathSegment());
Uri extendedPropertyURI = CalendarContract.ExtendedProperties.CONTENT_URI;
extendedPropertyURI = extendedPropertyURI.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Events.ACCOUNT_NAME, "...")
.appendQueryParameter(CalendarContract.Events.ACCOUNT_TYPE, "com.google").build();
ContentValues extendedValues = new ContentValues();
extendedValues.put(CalendarContract.ExtendedProperties.EVENT_ID, eventID);
extendedValues.put(CalendarContract.ExtendedProperties.NAME, "name");
extendedValues.put(CalendarContract.ExtendedProperties.VALUE, "valueA");
contentResolver.insert(extendedPropertyURI, extendedValues);
Now I want to update my extended property, let's say replace "valueA" with "valueB", here is what I do:
// update extended property
int propertyID = 123; // got this ID from CalendarContract.ExtendedProperties._ID, let me omit the code
ContentValues updatedValues = new ContentValues();
updatedValues.put(CalendarContract.ExtendedProperties.VALUE, "valueB");
Uri updateUri = ContentUris.withAppendedId(extendedPropertyURI, propertyID);
contentResolver.update(updateUri, updatedValues, null, null);
The extended property value gets updated successfully, I can see "valueB" on the device where the update has been executed. But it never syncs with Google Calendar server so other devices always show "valueA". I can observe the same behavior when I am trying to add another extended property to the same event - I can see both extended properties on current device only. New extended property never gets synced.
Can anyone please help to understand what I am doing wrong? I need to be able to add multiple extended properties to an event as well as edit these properties later.
P.S. Instead of attaching one single initial extended property, I could attach multiple extended properties to a new event in a loop, they all will be synced across devices successfully:
for (int i = 0; i < 10; i ++) {
ContentValues extendedValues = new ContentValues();
extendedValues.put(CalendarContract.ExtendedProperties.EVENT_ID, eventID);
extendedValues.put(CalendarContract.ExtendedProperties.NAME, "name");
extendedValues.put(CalendarContract.ExtendedProperties.VALUE, "value" + i);
contentResolver.insert(extendedPropertyURI, extendedValues);
}
So the syncing issue only occurs when I am trying to update an existing property or add (not at same time in a loop!) a new property to an event which already has "initial" extended properties.
The explanation is simple. All changes made by a sync adapter (including inserting/updating the extended properties) are not being synced with Google servers automatically by standard Android syncing mechanism. So if you need to sync the extended property local change, you need to make the related local event dirty (not by setting CalendarContract.Events.DIRTY=1 as it also requires using a sync adapter; running ContentResolver.insert/update without any actual changes is enough). As the event is dirty now and the event change does not come from a sync adapter, Android will automatically sync both the event and its extended properties soon.
It is important to update the local event before updating its extended properties. If you update the extended properties first, the change will be lost after Android completes syncing.
You may use 'Incremental sync' to perform repeatedly and updates the client with all the changes that happened ever since the previous sync. To do this, you need to perform a list request with your most recent sync token specified in the syncToken field.
Original query
GET /calendars/primary/events?maxResults=10&singleEvents=true&syncToken=CPDAlvWDx70CEPDAlvWDx
// Result contains the following
"nextPageToken":"CiAKGjBpNDd2Nmp2Zml2cXRwYjBpOXA",
Retrieving next page
GET /calendars/primary/events?maxResults=10&singleEvents=true&syncToken=CPDAlvWDx70CEPDAlvWDx&pageT
For more details regarding Incremental sync, follow this link: https://developers.google.com/google-apps/calendar/v3/sync#incremental_sync

Google Calendar return the result to Activity

Is it possible to get the selected event's result to Activity using Google calendar?
I'm using startActivityForResult to open the google calendar from my application, I would like get the selected event's details in my application on onActivityForResult method. Is it possible to override the select event in google calendar?
You can use the Google Calendar API to find and view public calendar events.
The Calendar API lets you display, create and modify calendar events as well as work with many other calendar-related objects, such as calendars or access controls.
GET https://www.googleapis.com/calendar/v3/calendars/calendarId/events
import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.model.Event;
// ...
// Initialize Calendar service with valid OAuth credentials
Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials)
.setApplicationName("applicationName").build();
// Retrieve an event
Event event = service.events().get('primary', "eventId").execute();
System.out.println(event.getSummary());
I believe you might find Google Calendar API really useful.
Reference Link https://developers.google.com/google-apps/calendar/v3/reference/events
This might be help you.Good Luck

Android HoneyComb - Requering already closed cursor

I read lots of questions about this problem but I can't find the right direction to my problem, maybe because I'm noob and feeling desperated to find the right way...
As far as I read, the "requering already closed cursor" problem happens since HoneyComb because startManagingCursor is deprecated. And since HoneyComb we should use the CursorLoader that works with ContentProvider (which I don't use and I don't want to), and found that someone wrote a class to use CursorLoader without ContentProvider (here).
On my application, I've a mySQLiteHelper class which I've lots of methods to retrieve data from SQLite like this one:
public Cursor listaBeneficios(String id) {
String where = "proposta=?";
String[] whereArgs = {id};
String[] campos = {"pessoa"};
Cursor c = db.query(TABLE_BENEFICIOS, campos, where, whereArgs, null, null, null, null);
if (c.moveToFirst()) {
return c;
} else {
return null;
}
}
And on my Activity, I could read the data like this:
db = new repositorio(MainActivity.this);
Cursor c = db.listaBeneficios(PROPOSTA);
startManagingCursor(c);
address.setText(c.getString(c.getColumnIndex("address")));
db.close();
But I noticed that it gives the infamous "trying to requery a allready closed cursor" everytime that I hit the back button and return to Activity A.
I've allready tried to stopManagingCursor and close() and not use startManagingCursor.
This is driving me nuts.
Is there any available simple examples of using CursorLoaders ?
Am I able to continue using the methods (ie, the listaBeneficios() above) above if I implement CursorLoaders?
Is this class helpful for me? how can I implement it?
Any kind help is appreciated.
A CursorLoader won't work because it requires a content URI. However, you can always use a Loader or AsyncTaskLoader. The documentation for these classes contains examples for how to use them.
In my case, I was using managedQuery to return a cursor to my activity from the ContentProvider. I simply changed the call to getContentResolver().query and problem solved.
Do a Control H in Eclipse to swap out all the changes you need.

Android Calendar API - edit/delete one event in a recurring series

I can add and delete a new recurring event, but how can I edit/delete one event in a recurring event using the new Android Calendar API? And if it is possible how do I update a reminder on one event?
Regards Daniel
Maybe this will help:
// First retrieve the instances from the API.
Events instances = service.events().instances("primary", "recurringEventId").execute();
// Select the instance to edit
Event instance = instances.getItems().get(0);
if(youWantToCancel) {
instance.setStatus("canceled");
instance.setReminders(yourReminders);
Event updatedInstance = service.events().update("primary", instance.getId(), instance).execute();
}
if(youWantToDelete){
instance.setId("ToBeDeleted")
service.events().delete("primary", instance.getId()).execute();
}
If you want to delete multiple events within a recurrence, simply set the ids to some obvious string like "ToBeDeleted" and perform: service.events().delete("primary",
"ToBeDeleted").execute();
See docs

How to get calendar event updates on Android device?

I want to get calendar event updates (when a new event is added or an existing event is deleted ) on android 2.2 devices ?
In other words, my program wants to get notifications for any calendar event changes
Anyone has any thoughts regarding how to do this?
whenever the Calendar update is made,u can get notification by using Content Observer,u have to register first observer using
this.getContentResolver().registerContentObserver(uri, true, observer);
where uri is the the calendar uri like "content://com.android.calendar/events" and observer is the object of the class extending Content Observer which overrides on change method,invoked when the change occurs
you have to notify this observer using
this.getContentResolver().notifyChange(eventsUri, null)
wherever u r performing changes like in read or delete operation of the calendar

Categories

Resources