androidcontactsrawcontacts

how to add an existing contact to the "Phone contacts" Account


iam adding a contact to the device using this code

long Contact_Id = 100;
ContentValues pCV =new ContentValues();
pCV.put(Contacts.People.NAME, "test");
pCV.put(ContactsContract.Contacts._ID, Contact_Id);
Uri newContactUri = insertContentValues(cResolver,
                    Contacts.People.CONTENT_URI, pCV);

i want to add this contact to a certain Account. iam using this code below

ContentResolver cResolver = context.getContentResolver();
cResolver.insert(uri, ContactsContract.RawContacts.CONTENT_URI,
                        getAccountType()); 

public ContentValues getAccountType() {
    ContentValues cv = new ContentValues();  
    cv.put(ContactsContract.RawContacts.ACCOUNT_TYPE,  "com.sonyericsson.localcontacts");
    cv.put(ContactsContract.RawContacts.ACCOUNT_NAME, "Phone contacts");
    return cv;
}

this code actually is adding a new contact to the "Phone contacts" Account. but i want to add the contact that i added above ("test") to be added to the "Phone contacts". how can i do so?


Solution

  • After searching I have found that the best way to insert a Contact to the Local Phone contacts is to assign the ACCOUNT_TYPE, ACCOUNT_NAME to null take a look at this Link