I am using calendar provider to create and delete events.
The problem occurs in some devices when I try to remove events. Android OS shows a notification saying:
"Too many Calendar deletes"
with options to proceed.
I couldn't find an answer to fix it in Android, only read about calendar API limitation. But it's unacceptable to offer a feature to clientes with this notification.
I am running the following line to remove an event:
context.getContentResolver().delete(eventUri, null, null);
Thanks!
I'm afraid, there is no "correct" way to bypass this message and you also shouldn't even try. This is shown because the sync adapter has set the tooManyDeletions flag in the SyncResult object to true
after trying to sync.
The sync manager will always show this message if the flag is set to true
.
The number of allowed deletions is defined by the respective sync adapter or by the API it's syncing to. So if you see the message depends on the account type and maybe even on the version of the sync adapter.
This is a mechanism to protect the user's data from being deleted due to a mistake (either by himself or by broken software).
You could try to trick the SyncManager and the sync adapter by triggering a sync on the respective account with the SYNC_EXTRAS_OVERRIDE_TOO_MANY_DELETIONS flag being set by your code, but you really shouldn't do that. Actually I would consider this a bug in Android if it works.
You should communicate this to the user and sell it as a feature.
To trigger a sync with SYNC_EXTRAS_OVERRIDE_TOO_MANY_DELETIONS
call this:
Bundle extras = new Bundle();
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
extras.putBoolean(ContentResolver.SYNC_EXTRAS_OVERRIDE_TOO_MANY_DELETIONS, true);
ContentResolver.requestSync(accountOfCalendar, CalendarContract.Authority, extras);
accountOfCalendar
is the account of the calendar that you deleted the events from.
Use it with care.