here a code snipped i used
newContactUri = null;
try {
ContentProviderResult[] res = globalContext.getContentResolver()
.applyBatch(ContactsContract.AUTHORITY, ops);
if (res != null && res[0] != null) {
newContactUri = res[0].uri;
/**
* als Ergebnis erhaelt man eine URI, mit der man die raw
* contact-id auslesen kann.
*/
if (debug) {
Log.d(TAG, "URI added contact:" + res[0].uri.toString()
+ " l: " + res.length);
}
subQuery(newContactUri); // setzt contactRawID
} else if (debug)
Log.e( ....);
} catch (Exception e) {
if (debug)
Log.d( .... );
}
and this is the subroutine subQuery
/**
* <pre>
* nachdem ein user angelegt ist, wird damit
* die contactRawID gesetzt
*
* @param contactUri
* ... Ergebnis aus ContentProviderResult
* @return void
* </pre>
*/
public void subQuery(Uri contactUri) {
if (debug)
Log.i(TAG, "subQuery() ");
contactRawID = -2;
// Content Resolver
String contactIdString = null;
String displayName = null;
ContentResolver contentResolver = globalContext.getContentResolver();
String[] mainQueryProjection = { ContactsContract.RawContacts._ID,
ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY };
Cursor subQueryCursor = contentResolver.query(contactUri,
mainQueryProjection, null, null, null);
if (subQueryCursor != null) {
if (debug)
Log.d(TAG, "subQueryCursor != null ");
while (subQueryCursor.moveToNext()) {
contactIdString = subQueryCursor.getString(0);
displayName = subQueryCursor.getString(1);
}
;
try {
subQueryCursor.close();
} catch (Exception e) {
if (debug)
Log.d(TAG, .... );
}
contactRawID = Integer.parseInt(contactIdString);
}
return;
}
many sorry for german comment text
but i hope this helps a little bit