Android-Content Provider Basics

来源:互联网 发布:淘宝退款率高会降权吗 编辑:程序博客网 时间:2024/06/05 17:06

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 with ContentResolver.applyBatch().
  • Asynchronous queries: You should do queries in a separate thread. One way to do this is to use aCursorLoader 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.
ContentProviderOperation  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
A provider defines URI permissions for content URIs in its manifest, using the android:grantUriPermissionattribute 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".





0 0
原创粉丝点击