Android: se agrega un nuevo registro de datos al contacto incorrecto

Estoy tratando de agregar un registro de datos a un contacto ya existente, encuentro el contacto usando la búsqueda telefónica, tomo el campo contact _id y agrego un nuevo dato con raw_contact_id establecido en el campo _id. en algunos contactos simplemente no funciona, hace coincidir los datos con diferentes contactos. (Creo que se relaciona con los contactos que están almacenados en la tarjeta SIM)

Por favor, consejos, tal vez tenga una forma diferente de agregar los datos

code muestra:

<pre><code>LinkedList<Long> lcv = new LinkedList<Long>(); ContentResolver cr = getContentResolver(); Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); Cursor c = cr.query(uri, null, null, null, null); try { while (c.moveToNext()) { Uri lookupUri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, c.getString(c.getColumnIndex(PhoneLookup.LOOKUP_KEY))); Cursor c2 = getContentResolver().query(lookupUri, new String[] { Contacts._ID, Contacts.DISPLAY_NAME }, null, null, null); try { if (c2.moveToNext()) { Log.i(TAG, "found: " + c2.getLong(c2.getColumnIndex(Contacts._ID)) + ", " + c2.getString(c2.getColumnIndex(Contacts.DISPLAY_NAME))); lcv.add(c2.getLong(c2.getColumnIndex(Contacts._ID))); } else { Log.e(TAG, "failed to lookup"); } } finally { c2.close(); } } } finally { c.close(); } for (Long rawid : lcv) { Cursor c3 = cr.query(RawContacts.CONTENT_URI, null, RawContacts.CONTACT_ID + "=?", new String[] {rawid+""}, null); if (c3.moveToNext()) { Log.e(TAG,"aaaa: " + c3.getString(c3.getColumnIndex(Contacts.DISPLAY_NAME))); } else { Log.e(TAG,"errrrror"); } ContentValues cv = new ContentValues(); cv.put(Data.RAW_CONTACT_ID, rawid + ""); cv.put(Data.MIMETYPE, MyMime.MIMETYPE); cv.put(Data.DATA1, "mydata"); cv.put(Data.SYNC1, syncvalue); Uri newIns = cr.insert(ContactsContract.Data.CONTENT_URI, cv); Log.i(TAG, "insert: " + newIns + ", " + name); } </code></pre>

Respuestas a la pregunta(1)

Su respuesta a la pregunta