开发者

Not able to update contact name in emulator 2.1

开发者 https://www.devze.com 2022-12-23 02:22 出处:网络
I am tring to update name of existing contact in android 2.1 emulator with the following code but always getting \"java.lang.IllegalArgumentException: Emplty values\" Exception.

I am tring to update name of existing contact in android 2.1 emulator with the following code but always getting "java.lang.IllegalArgumentException: Emplty values" Exception.

ContentValues contactValues = new ContentValues(); contactValues.put(People.NAME, "rishabh"); getContentResolver().update(UpdateContactUri, contactValues, null, null);

UpdateContactUri is the uri of existing contact with id 4. It is working on emulator 1.6 but not on 2.1.

One more thing i need to ask how can i access indivisual fields of Name(first, midd开发者_如何转开发le, last) and Address(Street, city, state, zip, country) in 2.1


in android 2.1, I use this hack code to update contact name:

public static void modifyPeopleName(ContentResolver cr, String id,
        String sName) {
    if (sName == null)
        return;

    ContentValues values = new ContentValues();
    int android_sdk_version = Integer.parseInt(Build.VERSION.SDK);
    if (android_sdk_version < 7) {
        values.put(People.NAME, sName);
        cr.update(People.CONTENT_URI, values, People._ID+"="+id, null);
    } else {
        values.put("data1", sName);
        cr.update(Uri.parse("content://com.android.contacts/data/"),
                values, "raw_contact_id=" + id, null);
    }
    return;
}
0

精彩评论

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

关注公众号