1

Till now I have followed the Sample Syncadapter example provided with the Android Sdk and able to add contact details like Phone Number and Name, but couldn't find any example on how to add and update a Postal Address through syncadapter. Please help me in this regard.

Matt
  • 22,721
  • 17
  • 71
  • 112

1 Answers1

1

Add this postal address right now check,

    // inserUri = name add uri 
    Uri addUri = Uri.withAppendedPath(insertUri, People.ContactMethods.CONTENT_DIRECTORY);
    ContentValues cv = new ContentValues();
    cv.put(People.ContactMethods.KIND,Contacts.KIND_POSTAL/Contacts.KIND_EMAIL);
    cv.put(People.ContactMethods.DATA, mEditText.getText().toString().trim());
    cv.put(People.ContactMethods.TYPE,  People.ContactMethods.TYPE_*);
    Uri updateUri = getContentResolver().insert(addUri, cv);

And update for check this code,

String selectProjectionAddress = ContactsContract.Data.CONTACT_ID + "=? AND " + 
        ContactsContract.Data.MIMETYPE + "='"  +
        ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE + "'" + " AND " + 
        ContactsContract.CommonDataKinds.StructuredPostal.TYPE + "=?";

if (editTextAddress.getText().toString().trim().length() > 0 ) {

     String[] args = new String[] { "yourContactsID", 
             String.valueOf(ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME) };

     ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)             
                        .withSelection(selectProjectionAddress, args)             
                        .withValue(ContactsContract.CommonDataKinds.StructuredPostal.DATA, 
                                editTextAddress.getText().toString().trim())             
                        .build());

} 
Najib.Nj
  • 3,706
  • 1
  • 25
  • 39