Reputation: 1
I would ask You for a help. Now I am writing an app, which takes current events from Google calendars. But problem is there, when I'm trying to output events from more than one calendar. I know, that I'm doing something wrong, but really, can't get in the problem..
public class Main extends Activity { //TextView mInfo; TextView mEvents; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //mInfo = (TextView)findViewById(R.id.info); mEvents = (TextView)findViewById(R.id.events); String[] calendarName = {"Calendar1", "Calendar2", "Calendar3", "Calendar4", "Calendar5"}; readCalendars(calendarName); } private void readCalendars(String[] calendarName) { String[] projection = new String[]{ CalendarContract.Calendars._ID, CalendarContract.Calendars.NAME, CalendarContract.Calendars.ACCOUNT_NAME, CalendarContract.Calendars.ACCOUNT_TYPE}; Cursor calCursor = getContentResolver(). query(CalendarContract.Calendars.CONTENT_URI, projection, CalendarContract.Calendars.VISIBLE + " = 1", null, CalendarContract.Calendars._ID + " ASC"); long calId = -1; //String calendarAccount = ""; for(int i = 0; i 0) { if(cursor.moveToFirst()) { do { long eventId = cursor.getLong(3); events += getEventInfo(eventId,cursor.getLong(1),cursor.getLong(2),cursor.getString(4),cursor.getString(5),cursor.getString(6)) + "\n"; } while(cursor.moveToNext()); } } mEvents.setText(events); } } @SuppressLint("SimpleDateFormat") private String getEventInfo(long eventId,long startTime, long endTime,String description, String location,String title) { String eventInfo = ""; { DateFormat df = new SimpleDateFormat("HH:mm"); String start = df.format( new Date(startTime)); String end = df.format( new Date(endTime)); eventInfo = start + "-" + end + " Class: "+ location + "\nLecture: " + title + "\nLecturer: " + description; } return eventInfo; } }
Tried to output all events with loop, but does not helps. If I pass in calendarName[i]
, where i is one of existing calendars, I get output of calendar, which I asked for, but that's only one calendar, but for example, I need to output 5 calendars.
Tried to do anything with ListView - failure again.
Hope, You would help with this problem or help somehow how to resolve it..
Upvotes: 0
Views: 285
Reputation: 485
The CalendarContract.Calendars.CONTENT_URI can be used to retrieve calendars, but not actual events for those calendars. Once you have the calendar id, you must use either of the following URIs for event information:
Upvotes: 0