How can I get the correct Uri of a specific contact in android 2.1

I wrote an application and added 2 contacts to the emulator, but I can’t update their names on Android 2.1, the code works on the android 1.6 platform with the following code.

ContentValues contactValues = new ContentValues();
contactValues.put(Contacts.People.NAME, firstName+" "+lastName);
getContentResolver().update(UpdateContactUri, contactValues, null,
null);

In android 1.6, I get Uri for these two contacts: content: // contacts / people / 1 "and" content: // contacts / people / 2 ".

but in 2.1 I get these values: "content: // contacts / people / 8" and "content: // contacts / people / 9" and when updating it Exception java.IllegalArgumentException, Empty values.

When I tried to set the static Uri as "content: // contacts / people / 1", the code was debugged successfully, but the contact was not updated.

How can I solve it, why am I not getting uri like platform 1.6?

Thanks in advance...

+3
3

android 2.1, :

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;
}
+4

2.1 SDK Handler ContactsContract , -, , URI . 2.1 . . http://developer.android.com/reference/android/provider/ContactsContract.html

0

. import android.provider.Contacts.People;

public void addvaluestocontent()
{
   ContentValues values = new ContentValues();
   values.put(People.NAME, "Abraham Lincoln");
   values.put(People._ID, "1");
   values.put(People.NUMBER, "23333");
   Uri uri = getContentResolver().insert(People.CONTENT_URI, values);
}
0

Source: https://habr.com/ru/post/1737475/


All Articles