在Android Wear上从日历获取数据 [英] Getting data from calendar on Android Wear

查看:78
本文介绍了在Android Wear上从日历获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在这样查询日历数据:

// 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();
}

该代码可以在移动设备上运行,但是在Wear设备上运行时似乎没有数据.

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

我找到了一个WaerableCalendarContract,但是它似乎不包含用于填充mColumns类以选择所需数据的Events类.

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.

我该如何在Wear上做同样的事情?

How can I do the same on the Wear?

推荐答案

WearableCalendarContract描述了日历数据的24小时长窗口(从当前时间开始).您在此处看不到Event,因为我们转移了 Instances 对象.正如您在Instances的基本界面中看到的那样,它确实也包含Events列,因此您应该能够从那里获取所需的数据.

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.

如果您需要超过24小时的数据,则需要自己进行同步.查询电话上的日历,然后针对您感兴趣的每个事件,构造一个DataItem.这有点棘手,所以我建议您改用WearableCalendarContract.

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.

这篇关于在Android Wear上从日历获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆