contacts coding help

account manager api

account api


public void testAccounts()
{
    AccountManager am = AccountManager.get(this.mContext); 
    Account[] accounts = am.getAccounts();
    for(Account ac: accounts)
    {
        String acname=ac.name;
        String actype = ac.type;
        this.mReportTo.reportBack(tag,acname + ":" + actype);
    }
}

<uses-permission android:name="android.permission.GET_ACCOUNTS"/>

contactscontract api

contact uri


private void printCursorColumnNames(Cursor c)
{
    int count = c.getColumnCount();
    StringBuffer cnamesBuffer = new StringBuffer();
    for (int i=0;i<count;i++)
    {
        String cname = c.getColumnName(i);
        cnamesBuffer.append(cname).append(';');
    }
    this.mReportTo.reportBack(tag,cnamesBuffer.toString());
}
private Cursor getContacts()
{
    // Run query
    Uri uri = ContactsContract.Contacts.CONTENT_URI;
    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME 
                         + " COLLATE LOCALIZED ASC";
    Activity a = (Activity)this.mContext;
    return a.managedQuery(uri, null, null, null, sortOrder);
}

Notice how the projection is passed as null. Subsequently we go after the column count and column names based on index. Useful for debugging.


times_contacted;
contact_status;
custom_ringtone;
has_phone_number;
phonetic_name;
phonetic_name_style;
contact_status_label;
lookup;
contact_status_icon;
last_time_contacted;
display_name;
sort_key_alt;
in_visible_group;
_id;
starred;
sort_key;
display_name_alt;
contact_presence;
display_name_source;
contact_status_res_package;
contact_status_ts;
photo_id;
send_to_voicemail;

Source code of viewcontactactivity

Hoping to find the answer to how contacts are aggregated

Looks like that was the old version. Here is the 2.0 source code

Here is the source code for the contacts provider

How to read an android aggregated contact

Search for: How to read an android aggregated contact

How can I construct an android contact lookup uri

Search for: How can I construct an android contact lookup uri

How can I read various raw contact ids based on an aggregated contact

Search for: How can I read various raw contact ids based on an aggregated contact

How does the contacts application fire off the lookup uri

Search for: How does the contacts application fire off the lookup uri

Does the contacts application read the raw contacts for displaying an aggregated contact

Search for: Does the contacts application read the raw contacts for displaying an aggregated contact

Read up on contact lookup uri


Contact name: 
C3-first C3-last

lookup url:
content://com.android.contacts/contacts/lookup
/2582r3-302982363C4E5052302982422C5052

The last part of this url is the lookup key for that contact


private String getLookupKey(Cursor cc)
{
 int lookupkeyIndex = 
    cc.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY);
 return cc.getString(lookupkeyIndex);
}

private String getLookupUri(String lookupkey)
{
    String luri = 
       ContactsContract.Contacts.CONTENT_LOOKUP_URI + "/" + lookupkey;
    return luri;
}

times_contacted;
contact_status;
custom_ringtone;
has_phone_number;
phonetic_name;
phonetic_name_style;
contact_status_label;
lookup;
contact_status_icon;
last_time_contacted;
display_name;
sort_key_alt;
in_visible_group;
_id;
starred;
sort_key;
display_name_alt;
contact_presence;
display_name_source;
contact_status_res_package;
contact_status_ts;
photo_id;
send_to_voicemail;

uri
projection
selection
selectionargs
sortorder

times_contacted;
 phonetic_name;
 phonetic_name_style;
 contact_id;version;
 last_time_contacted;
 aggregation_mode;
 _id;
 name_verified;
 display_name_source;
 dirty;
 send_to_voicemail;
 account_type;
 custom_ringtone;
 sync4;sync3;sync2;sync1;
 deleted;
 account_name;
 display_name;
 sort_key_alt;
 starred;
 sort_key;
 display_name_alt;
 sourceid;

public class AggregatedContact 
{
    public String id;
    public String lookupUri;
    public String lookupKey;
    public String displayName;
    
    public void fillinFrom(Cursor c)
    {
        id = Utils.getColumnValue(c,"_ID");
        lookupKey = Utils.getColumnValue(c,ContactsContract.Contacts.LOOKUP_KEY);
        lookupUri = ContactsContract.Contacts.CONTENT_LOOKUP_URI + "/" + lookupKey;
        displayName = Utils.getColumnValue(c,ContactsContract.Contacts.DISPLAY_NAME);
    }
}

public class RawContact 
{
    public String rawContactId;
    public String aggregatedContactId;
    public String accountName;
    public String accountType;
    public String displayName;
    
    public void fillinFrom(Cursor c)
    {
        rawContactId = Utils.getColumnValue(c,"_ID");
        accountName = Utils.getColumnValue(c,ContactsContract.RawContacts.ACCOUNT_NAME);
        accountType = Utils.getColumnValue(c,ContactsContract.RawContacts.ACCOUNT_TYPE);
        aggregatedContactId = Utils.getColumnValue(c,ContactsContract.RawContacts.CONTACT_ID);
        displayName = Utils.getColumnValue(c,"display_name");
    }
    public String toString()
    {
        return displayName
            + "/" + accountName + ":" + accountType
            + "/" + rawContactId
            + "/" + aggregatedContactId;
    }
}

data_version;
contact_id;
version;
data12;data11;data10;
mimetype;
res_package;
_id;
data15;data14;data13;
name_verified;
is_restricted;
is_super_primary;
data_sync1;dirty;data_sync3;data_sync2;
data_sync4;account_type;data1;sync4;sync3;
data4;sync2;data5;sync1;
data2;data3;data8;data9;
deleted;
group_sourceid;
data6;data7;
account_name;
data_id;
starred;
sourceid;
is_primary;