顯示具有 androidContact 標籤的文章。 顯示所有文章
顯示具有 androidContact 標籤的文章。 顯示所有文章

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开发网

2011年11月6日 星期日

[Android] INVITE_CONTACT: No activity

Error Message

Loaded meta-data for 2 account types, 1 accounts in 111ms(wall) 46ms(cpu)
START {act=com.android.contacts.action.INVITE_CONTACT dat=content://com.android.contacts/contacts/lookup/0r1-1C1C1C1E/1 cmp=com.example.android.samplesync/.activities.InviteContactActivity} from pid 324
No activity found for intent: Intent { act=com.android.contacts.action.INVITE_CONTACT dat=content://com.android.contacts/contacts/lookup/0r1-1C1C1C1E/1 cmp=com.example.android.samplesync/.activities.InviteContactActivity }


press "Connection" -> "SampleSyncAdapter" on Android4.0 emulator contact app

2011年11月3日 星期四

[Android] SecurityException: Neither user 10043 nor current process has android.permission.READ_PROFILE.

Error Message

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{.ContactProfileTestActivity}: java.lang.SecurityException: Neither user 10043 nor current process has android.permission.READ_PROFILE.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
at android.app.ActivityThread.access$600(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.SecurityException: Neither user 10043 nor current process has android.permission.READ_PROFILE.
at android.os.Parcel.readException(Parcel.java:1327)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
at android.content.ContentResolver.query(ContentResolver.java:304)
at com.yellow.contact.ContactProfileTestActivity.getProfile(ContactProfileTestActivity.java:30)
at com.yellow.contact.ContactProfileTestActivity.onCreate(ContactProfileTestActivity.java:24)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
... 11 more


Occurred when query ME profile...