cur = null; cr = getContentResolver(); // Construct the query with the desired date range. Uri.Builder builder = Instances.CONTENT_URI.buildUpon(); ContentUris.appendID(builder,0); ContentUris.appendID(builder,endMillis); // submit the query cur = cr.query(builder.build(),INSTANCE_PROJECTION,null,null);
但是如你所见,我只能在给定的持续时间内获得事件,但我需要所有事件(没有任何时间规范,不包括重复事件)这可能吗?如何 ?
请帮我.
cur = cr.query(Uri.parse("content://com.androID.calendar/events"),null);
它给出了错误java.lang.IllegalArgumentException:
解决方法 试试这个代码……public class Utility { public static ArrayList<String> nameOfEvent = new ArrayList<String>(); public static ArrayList<String> startDates = new ArrayList<String>(); public static ArrayList<String> endDates = new ArrayList<String>(); public static ArrayList<String> descriptions = new ArrayList<String>(); public static ArrayList<String> readCalendarEvent(Context context) { Cursor cursor = context.getContentResolver() .query( Uri.parse("content://com.androID.calendar/events"),new String[] { "calendar_ID","Title","description","dtstart","dtend","eventLocation" },null); cursor.movetoFirst(); // fetching calendars name String Cnames[] = new String[cursor.getCount()]; // fetching calendars ID nameOfEvent.clear(); startDates.clear(); endDates.clear(); descriptions.clear(); for (int i = 0; i < Cnames.length; i++) { nameOfEvent.add(cursor.getString(1)); startDates.add(getDate(Long.parseLong(cursor.getString(3)))); endDates.add(getDate(Long.parseLong(cursor.getString(4)))); descriptions.add(cursor.getString(2)); Cnames[i] = cursor.getString(1); cursor.movetoNext(); } return nameOfEvent; } public static String getDate(long milliSeconds) { SimpleDateFormat formatter = new SimpleDateFormat( "dd/MM/yyyy hh:mm:ss a"); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(milliSeconds); return formatter.format(calendar.getTime()); }}
你也可以检查一下
Getting events from calendar
总结以上是内存溢出为你收集整理的android – 如何从日历中获取所有事件?全部内容,希望文章能够帮你解决android – 如何从日历中获取所有事件?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)