user_4685247
user_4685247

Reputation: 2995

Getting data from calendar on Android Wear

I'm querying the calendar data like this:

// Constructor of the class
mCursor = context.getContentResolver().query(CalendarContract.Events.CONTENT_URI, mColumns, null, null, null);
updateEvents();

//contents of updateEvents:
events.clear();
mCursor.moveToFirst();
mLastUpdate = System.currentTimeMillis();
while (!mCursor.isAfterLast())
{
    long end = mCursor.getLong(2);
    if (end > mLastUpdate)
        events.add(new Event(mCursor));

    mCursor.moveToNext();
}

The code manages works on mobile device, however when it's run on a Wear device there appears to be no data.

I've found a WaerableCalendarContract, but it doesn't seem to contain the Events class that I use to fill the mColumns class to select the desired data.

How can I do the same on the Wear?

Upvotes: 3

Views: 473

Answers (2)

gruszczy
gruszczy

Reputation: 42188

WearableCalendarContract describes a 24 hour long window (starting from the current time) of calendar data. You don't see Event there, because we transfer Instances objects. As you can see in base interface for Instances, it does include Events columns too, so you should be able to fetch the data that you need from there.

If you need more than 24 hours of data, you will need sync it yourself. Query the calendar on the phone and then for each event that interests you, construct a DataItem. This is a little tricky, so I would recommend using the WearableCalendarContract instead.

Upvotes: 2

Vesko
Vesko

Reputation: 3760

I think you have to sync your data to the Wear app manually, a.k.a fetch it from the ContentProvider on the phone and then send it to the wearable via the DataItem API. Read more about syncing data between phone<->wear HERE.

Upvotes: 0

Related Questions