Android 日历事件 [英] Android Calendar Events

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

问题描述

我只是在使用日历内容提供程序进行操作,现在我无法显示特定日期的事件.

I am just making an operation with Calendar Content Provider, now I am failing at the point to display events for the particular date.

我知道 < 的事件 URI.2.1版本和2.2版本,如下:

I know the Events URI for the < 2.1 version and 2.2 version, as below:

eventsUri = Uri.parse("content://calendar/events");    // < Android 2.1 version

eventsUri = Uri.parse("content://com.android.calendar/events");  // For Android Froyo 2.2 and later version

我的疑惑是:

  1. 如何获取所有事件?
  2. 如何获取特定日期的事件?

所以,请了解日历的人帮助我并分享您的相关知识.

So please, somebody with knowledge about the Calendar please help me and share your knowledge regarding this.

感谢

推荐答案

这些示例适用于 <= 2.1 版本;

These examples are for <= 2.1 version;

首先;找出存在哪些日历

first; find out which calendars exist

Cursor cursor = cr.query(Uri.parse("content://calendar/calendars"), new String[]{ "_id",  "displayname" }, null, null, null);
cursor.moveToFirst();
String[] CalNames = new String[cursor.getCount()];
int[] CalIds = new int[cursor.getCount()];
for (int i = 0; i < CalNames.length; i++) {
    CalIds[i] = cursor.getInt(0);
    CalNames[i] = cursor.getString(1);
    cursor.moveToNext();
}
cursor.close();

获取所有事件,特定事件通过指定范围完成
ContentResolver contentResolver = getContentResolver();

Fetching all events, and particular event is done by specifying range
ContentResolver contentResolver = getContentResolver();

Uri.Builder builder = Uri.parse(getCalendarUriBase() + "/instances/when").buildUpon();
        long now = new Date().getTime();
        ContentUris.appendId(builder, now - DateUtils.MILLIS_PER_DAY*10000);
        ContentUris.appendId(builder, now + DateUtils.MILLIS_PER_DAY * 10000);

然后假设您希望记录 ID = 1 的日历中的事件 ID

and then let's say you wish to log events ID from calendar with ID = 1

Cursor eventCursor = contentResolver.query(builder.build(),
                new String[] { "event_id"}, "Calendars._id=" + 1,
                null, "startDay ASC, startMinute ASC"); 
        // For a full list of available columns see http://tinyurl.com/yfbg76w
        while (eventCursor.moveToNext()) {
            String uid2 = eventCursor.getString(0);
            Log.v("eventID : ", uid2);

        }

这篇关于Android 日历事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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