3

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?

2 Answers 2

2

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.

4
  • so I assume WearableCalendarContract is synced automatically all the time? Jul 16, 2015 at 15:34
  • Yes, whenever the calendar changes, we will sync the data. The exception are attendees, which will be throttled to once per hour.
    – gruszczy
    Jul 16, 2015 at 16:01
  • Hi! Would you be able to point me to a sample app which shows how to use WearableCalendarContract? When I try to use the above contract on wearOS emulator, the contract keeps returning 0 values. Jun 24, 2019 at 20:15
  • Sorry, I haven't worked on Android Wear for many years :( You will need to look into the official documentation.
    – gruszczy
    Jun 25, 2019 at 16:06
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.