1

I'm currently working on an application, where we are going to be adding contacts from our own application, similar to how LinkedIn has connections and Facebook has friends. Therefore we want our custom account, that is shown in the images below (as "MyAppName") with the contacts added from our application:

We currently have a SyncAdapter as seen from the first image, as just wish for this to be shown in the Contacts application. We've been looking at documentation, but couldn't find anything specific to this.

This is not about adding contacts, but getting the account to show up in the contacts application under "Accounts".

ASamsig
  • 446
  • 3
  • 16
  • 1
    the contact data is separate from the accountmanager and sync-adapter. You'll have to be making calls to the system ContentProviders to add your custom data: http://stackoverflow.com/questions/2733589/how-to-add-new-fields-to-the-contact and here http://developer.android.com/guide/topics/providers/contacts-provider.html – Budius Mar 06 '13 at 10:19
  • Having read through the material you linked, I don't think the first thread has the answer, I can see it's about adding custom data fields, and I have already done this, so it's not really what I'm looking for. The second link however let me to look at ContactsContract.Groups and such, yet they are still groups and not an Account like what I'm interested in. If you have any more information that could be helpful I'd really appreciate it. – ASamsig Mar 06 '13 at 13:15
  • hi, the 1st thread is just a quick look on actual implementation. And the second, that's exactly it, I promise you. A contact have N number of accounts (called RawContact) and each rawContact have a bunch of properties like e-mail address, phone number, status, etc. This data is what is shown in the Contact app. On that link also there's a specific header for `Contacts Provider Sync Adapters` that starts with: "The Contacts Provider is specifically designed for handling synchronization of contacts data between a device and an online service." – Budius Mar 06 '13 at 14:22
  • I've already tied the users to my "MyAppName"-account, and they show up as a "MyAppName" contact, but yet there is no "MyAppName"-account under "Accounts". Am I missing something, or is there more to it than that? – ASamsig Mar 06 '13 at 14:57

1 Answers1

4

After having studied Budius' suggestions, I finally figured out how to do it. Here is a more precise link to the place where it's stated in the documentation. Basically you just need to make your account visible. Other than that, I found the answer on how to do that here.

ContentProviderClient client = getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY_URI);
ContentValues values = new ContentValues();
values.put(ContactsContract.Groups.ACCOUNT_NAME, account.name);
values.put(Groups.ACCOUNT_TYPE, account.type);
values.put(Settings.UNGROUPED_VISIBLE, true);
try
{
   client.insert(Settings.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build(), values);
}
catch (RemoteException e)
{
   e.printStackTrace();
}

All credit for this code goes to Henry Pushel.

Community
  • 1
  • 1
ASamsig
  • 446
  • 3
  • 16