Getting data from calendar on Android Wear

谁都会走 提交于 2019-12-07 16:53:57

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/31454677/getting-data-from-calendar-on-android-wear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!