With ICS, we now have APIs for the Calendar! :)
My question is, how do we determine if an event has been updated. Ideally this could be done with a BroadcastReceiver, but I don't think there is one that is publicly accessible. There is some event broadcasted, but I don't think it's accessible to non-system apps.
02-06 23:05:05.316: I/CalendarProvider2(9201): Sending notification intent: Intent { act=android.intent.action.PROVIDER_CHANGED dat=content://com.android.calendar }
02-06 23:05:05.320: W/ContentResolver(9201): Failed to get type for: content://com.android.calendar (Unknown URL content://com.android.calendar)
This is my work around for now. Is there a better way? Users can get squimish if they see a service running for along time and often will kill it to save battery life.
public class CalendarUpdatedService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
int returnValue = super.onStartCommand(intent, flags, startId);
getContentResolver().registerContentObserver(
CalendarContract.Events.CONTENT_URI, true, observer);
return returnValue;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
ContentObserver observer = new ContentObserver(new Handler()) {
@Override
public boolean deliverSelfNotifications() {
return true;
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
//code goes here to update
}
};
}