2011年11月7日 星期一

[Android] Contact APIs

[ContactsContract]
  • 是最根本的資料所在(?),而其下延伸出的資料儲存方式(db),有待再瞭解...。
  • The contract between the contacts provider and applications.
  • Contains definitions for the supported URIs and columns.
  • These APIs supersede ContactsContract.Contacts. (?)
  • Overview ContactsContract defines an extensible database of contact-related information. Contact information is stored in a three-tier data model:
    • A row in the ContactsContract.Data table
      • Data is a generic table that can hold any kind of contact data.
      • 連絡人的所有資料,每筆資料可能存有不同 type。
      • Can store any kind of personal data, such as a phone number or email addresses.
      • Contains data points tied to a raw contact
      • Each row of the data table is typically used to store a single piece of contact information (such as a phone number) and its associated metadata (such as whether it is a work or home number).
      • The set of data kinds that can be stored in this table is open-ended.
      • There is a predefined set of common kinds, but any application can add its own data kinds. ex:
        • ContactsContract.CommonDataKinds.Phone
        • ContactsContract.CommonDataKinds.Email...etc.
    • A row in the ContactsContract.RawContacts table
      • Represents a set of data describing a person and associated with a single account.
      • Contains one row of contact information for each person in each synced account.
      • Sync adapters and contact management apps are the primary consumers of this API.
      • 在一個帳號中的一位聯絡人的一筆資料。
      • ex: one of the user's Gmail accounts.
    • A row in the ContactsContract.Contacts table
      • Represents an aggregate of one or more RawContacts presumably describing the same person.
      • RawContact 的整合。
      • When data in or associated with the RawContacts table is changed, the affected aggregate contacts are updated as necessary.

[New APIs in Level 14]

[SampleSyncAdapter - Sample Sync Adapter | Android Developers]
  • The sample uses two related parts of the Android framework:
    • The account manager
    • The synchronization manager (through a sync adapter).
  • It also demonstrates how to provide users the ability to create and edit synchronized contacts using a custom editor.
  • Account Manager
    • The account manager allows sharing of credentials across multiple applications and services.
    • Users enter the credentials for each account only once
    • Applications with the USE_CREDENTIALS permission can then query the account manager to obtain an auth token for the account.
    • An authenticator (a pluggable component of account manager)
      • Requests credentials from the user
      • Validates them with an authentication server running in the cloud
      • Stores them to the account manager.
    • This sample demonstrates how to write an authenticator for your service by extending the new AbstractAccountAuthenticator abstract class.
  • SyncAdapter
    • The sync adapter (essential to the synchronization service) declares the account type and ContentProvider authority to the sync manager.
    • This sample demosntrates how to write your own sync adapters
      • By extending the AbstractThreadedSyncAdapter abstract class.
      • Implementing the onPerformSync() method, which gets called whenever the sync manager issues a sync operation for that sync adapter.


* Reference
- ContactsContract | Android Developers
- ContactsContract.Contacts | Android Developers
- Android联系人数据库 | Android开发网

沒有留言:

張貼留言