This topic describes the basics of the following:
- How content providers work.
- The API you use retrieve data from a content provider.
- The API you use to insert, update, or delete data in a content provider.
- Other API features that facilitate working with providers.
An application accesses the data from a content provider with a
ContentResolver
client object.
The
ContentResolver
methods provide the basic "CRUD" (create, retrieve, update, and delete) functions of persistent storage.
权限:android.permission.READ_USER_DICTIONARY;android.permission.WRITE_USER_DICTIONARY
<uses-permission android:name="android.permission.READ_USER_DICTIONARY">
Three alternative forms of provider access are important in application development:
- Batch access: You can create a batch of access calls with methods in the
ContentProviderOperation
class, and then apply them withContentResolver.applyBatch()
. - Asynchronous queries: You should do queries in a separate thread. One way to do this is to use a
CursorLoader
object. The examples in the Loaders guide demonstrate how to do this. - Data access via intents: Although you can't send an intent directly to a provider, you can send an intent to the provider's application, which is usually the best-equipped to modify the provider's data.
ContentResolver.applyBatch()
.
The application that has permanent permissions grants temporary permissions by setting a flag in the result intent:
- Read permission:
FLAG_GRANT_READ_URI_PERMISSION
- Write permission:
FLAG_GRANT_WRITE_URI_PERMISSION
android:grantUriPermission
attribute of the
<provider>
element, as well as the
<grant-uri-permission>
child element of the
<provider>
element. The URI permissions mechanism is explained in more detail in the
Security and Permissions
guide, in the section "URI Permissions".