1

到目前为止,我一直遵循 Android Sdk 提供的 Sample Syncadapter 示例,并且能够添加电话号码和姓名等联系人详细信息,但找不到任何有关如何通过同步适配器添加和更新邮政地址的示例。请在这方面帮助我。

4

1 回答 1

1

立即添加此邮政地址检查,

    // 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);

并更新以检查此代码,

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());

} 
于 2012-12-10T05:14:07.337 回答