我正在按此代码保存联系人

ArrayList<ContentProviderOperation> ops =
          new ArrayList<ContentProviderOperation>();
 ...
 int rawContactInsertIndex = ops.size();
 ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
          .withValue(RawContacts.ACCOUNT_TYPE, accountType)
          .withValue(RawContacts.ACCOUNT_NAME, accountName)
          .build());

 ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
          .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
          .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
          .withValue(StructuredName.GIVEN_NAME, linkname1)
          .withValue(StructuredName.FAMILY_NAME, linkname2)
          .build());

 getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);

保存联系人后,我需要获取“id”字段,以便从联系人簿中获取该联系人以进行编辑。我怎样才能在保存后得到身份证?
提前谢谢

最佳答案

ContentProviderResult[] res = getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);

Uri myContactUri = res[0].uri;
int contactID = Integer.parseInt(myContactUri.getLastPathSegment());

07-26 09:32