开发者

Add city to postal address when adding contact - Android

I am adding a contact through an Intent and am unable to figure out how to开发者_运维百科 add the City to the Postal Address. Using ContactsContract.Intents.Insert.POSTAL as the key, allows me to put the address in:

intent.putExtra(ContactsContract.Intents.Insert.POSTAL ,cm.getAddress());

but I'm not sure how to add the city. In the API I see:

ContactsContract.CommonDataKinds.StructuredPostal.CITY

but I'm not sure how to use this.

Thanks for any ideas on this. I searched the Demos, but couldn't find anything.

Regards, Julius.


I am updating a contact's postal address through ContentResolver. If it helps here is my working code:

ContentValues cv = new ContentValues();
       cv.put(Data.RAW_CONTACT_ID, contactId);
       cv.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE);
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.STREET, streetAddress);
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.CITY, city);
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.REGION, province);
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE, postalCode);
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY, country);
        int addressType = ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME;
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.TYPE, addressType);

        try {
            getContentResolver().insert(ContactsContract.Data.CONTENT_URI, cv);
        } catch(Exception e)    {
            Log.i(TAG, e.getMessage());
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜