通过SyncAdapter添加和更新邮政地址

时间:2012-09-13 07:57:56

标签: android android-syncadapter street-address

到目前为止,我已经按照随Android Sdk提供的示例Syncadapter示例,并能够添加电话号码和姓名等联系人详细信息,但无法找到有关如何通过syncadapter添加和更新邮政地址的任何示例。请帮助我。

1 个答案:

答案 0 :(得分: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());

}