我只是在使用日历内容提供程序进行操作,现在我无法显示特定日期的事件.
我知道<的事件URI 2.1版和2.2版,如下:
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
我的怀疑是:
所以,有关日历知识的人请帮助我并分享您对此的了解.
感谢名单
解决方法
这些例子适用于< = 2.1版本; 第一;找出存在哪些日历
Cursor cursor = cr.query(Uri.parse("content://calendar/calendars"),new String[]{ "_id","displayname" },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();
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
Cursor eventCursor = contentResolver.query(builder.build(),new String[] { "event_id"},"Calendars._id=" + 1,"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); }