nope5035 nope5035 - 6 months ago 13
Android Question

WearableCalendarContract query "Sort order is not supported" error

I'm getting a

Sort order is not supported
error when trying to apply a sort order to my query. The query runs just fine if the sort order is null. Can anyone help me here? Code is below:

long currentTime = System.currentTimeMillis();
Uri.Builder builder = WearableCalendarContract.Instances.CONTENT_URI.buildUpon();
ContentUris.appendId(builder, currentTime);
ContentUris.appendId(builder, currentTime + DateUtils.DAY_IN_MILLIS);

final String[] PROJECTION = {
CalendarContract.Calendars._ID, // 0
CalendarContract.Instances.BEGIN, // 1
CalendarContract.Instances.END, // 2
CalendarContract.Events.DISPLAY_COLOR, // 3
CalendarContract.Events.TITLE, // 4
CalendarContract.Events.ALL_DAY // 5
};

final Cursor cursor = getContentResolver()
.query(builder.build(),
PROJECTION,
null, // selection (all)
null, // selection args
CalendarContract.Instances.BEGIN + " ASC"); // order

Answer

Exactly as the error message says, WearableCalendarContract.Instances.CONTENT_URI does not support sorting. It is a completely separate implementation from CalendarContract, even though it shares the same fields.