Can anyone explain me about each term that I have used in working with calendar events?
-
Uri event_uri = Uri.parse("content://com.android.calendar/" + "events");
What is uri here, what actually is content, as we can initialize int value to 0? Is it
possible to initialize a uri with a default value? -
Uri reminder_uri = Uri.parse("content://com.android.calendar/" + "reminders");
What signifies these uri? What are the differences betweenevent_uriandreminder_uri? -
ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", str);
values.put("description", m_strDescription);
What does the first one do?values.put("calendar_id", 1); -
ContentResolver cr = getContentResolver();
What is the use of the content resolver? Sometimes we write:Uri u = cr.insert(event_uri, values)
What is this uri? How does it differ from the first two uris e.gevent_uriandreminder_uriAgain
values.put("event_id", Long.parseLong(event.getLastPathSegment()));
cr.insert(remindar_uri, values);What does it do?
Regarding questions 1 and 2, A
Uriis an address that points to something of significance. In the case ofContentProviders, theUriis usually used to determine which table to use. Soevent_uripoints to the events table and thereminder_uripoints to the reminders table. There is really no “default value” for uris.Regarding question 3, the
ContentValuesis essentially a set of key-value pairs, where the key represents the column for the table and the value is the value to be inserted in that column. So in the case ofvalues.put("calendar_id", 1);, the column is “calendar_id” and the value being inserted for that column is 1.Regarding question 4, the
ContentResolveris what android uses to resolveUris toContentProviders. Anyone can create aContentProviderand Android hasContentProviders for the Calendar, Contacts, etc.. Theinsert()method on aContentResolverreturns theUriof the inserted row. So in questions 1 and 2, thoseUris pointed to the table butUris are hierarchical so they can resolve to a specific row. For example:content://com.android.calendar/eventspoints to the events table, butcontent://com.android.calendar/events/1points to the row in the events table with id 1.Keep in mind, that this is the usual behavior, but the providing
ContentProvidercan customize the uris to be resolved differently.I would strongly recommend reading the ContentProvider docs, especially the section on Content URIs.
From the previously recommended documentation: