Structure of android Content URIs

We compared a content provider to a web site because it responds to incoming URIs. So, to retrieve data from a content provider, all you have to do is invoke a URI. The retrieved data in the case of a content provider, however, is in the form of a set of rows and columns represented by an Android cursor object. In this context, we'll examine the structure of the URIs that you could use to retrieve data.

Content URIs in Android look similar to HTTP URIs, except that they start with content and have this general form:

Here's an example URI that identifies a note numbered 23 in a database of notes:

content://com.google.provider.NotePad/notes/23

After content:, the URI contains a unique identifier for the authority, which is used to locate the provider in the provider registry. In the preceding example, com.google.provider. NotePad is the authority portion of the URI.

/notes/23 is the path section of the URI that is specific to each provider. The notes and 23 portions of the path section are called path segments. It is the responsibility of the provider to document and interpret the path section and path segments of the URIs. The developer of the content provider usually does this by declaring constants in a Java class or a Java interface in that provider's implementation Java package. Furthermore, the first portion of the path might point to a collection of objects. For example, /notes indicates a collection or a directory of notes, whereas /23 points to a specific note item.

Given this URI, a provider is expected to retrieve rows that the URI identifies. The provider is also expected to alter content at this URI using any of the state-change methods: insert, update, or delete.

0 0

Post a comment