Question

For more than two days now, I'm trying to grab a list of all contacts, from the internal addressbook (no facebook-, gmail- or twittercontacts) with their family- and givenname.

I managed to get a list with all contacts, socialcontacts included. So I looked at the account_types and saw that on my HTC Desire all the internal addressbook-contacts were from "com.htc.android.pcsc" and I was like "Great, I just have to filter the whole list". But then all people with non-htc android cellphones would be unable to use my app, if I would hardcode this filter.

Next idea was to let the user choose which account he wants to use, but unfortunately the "com.htc.android.pcsc" didn't appear in the list I got from the AccountManager?!?

So my question is: Is there any standardized way to access the internal adressbook? I'm really stuck with that and any hint is highly appreciated!

/edit: Maybe i didn't make my self clear enough. I can grab a contactlist, via the ContactsContract API:

ArrayList phoneContacts = new ArrayList();   
String[] projection = new String[] {
    Data.MIMETYPE,
    ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
    ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME
   };
String selection =  Data.MIMETYPE+" = '"+ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE+"'";
Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, projection, selection, null, null);
while (cursor.moveToNext()) {
phoneContacts.add(...);
} 
cursor.close();

But then I have contacts from all the different accounttypes, like com.google / com.htc.socialnetwoork.facebook, etc.

And my question is: How can I filter all these socialnetwork- and gmailcontacts out, so I have a list with contacts, which are only from my internal addressbook?

/edit2: I found an example which describe the same difficulty I have: http://forum.synthesis.ch/showthread.php?t=2057 Synthesis AG had the same problem with their SyncML, that people complaining that they can't sync with their internal addressbook/phonebook only with gmail, facebook, etc. But they managed to seperate the internal addressbook from all these other accounttypes. So there must be a way to solve this problem, but I can't figure out how. Please help!

Was it helpful?

Solution

OTHER TIPS

Do you actually have to care about the account types?
Just retrieve the aggregated top-level contacts — rather than each individual raw contact — and use that as your contact list.

For example, I have many contacts who are linked together into one contact entry, even although there are multiple underlying raw contact entries (e.g. from my Google Account, or Facebook etc.).

If you filtered out all the individual Google and Facebook contacts from my phonebook, you'd be left with nothing. Or if you listed all raw contacts, you'd have 90 contacts, with many duplicates, instead of just 50 actual people.

So, the account type shouldn't matter if you just retrieve aggregated contacts.

When you add a contact to your phone's address book, you have to set ACCOUNT_NAME and ACCOUNT_TYPE to null. But device changes these values to some appropriate name and type and these values aren't the same for different manufactures.

I don't know any really good way to filter out all accounts except the address book account. I see only to ways to implement such behavior, but both of them seems to be not so good:

  1. You can get a list of accounts and filter out any contact with account from this list. Contacts from SIM with "com.anddroid.contacts.sim" account type must be filtered out too.
  2. You can save a fake contact to the internal address book, then find it and determine its account type. It can be done only once, for example on the first launch of your app.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top