/** * Parses the given URI to determine the original lookup key of the contact. */ public static String getLookupKeyFromUri(Uri lookupUri) { // Would be nice to be able to persist the lookup key somehow to avoid having to parse // the uri entirely just to retrieve the lookup key, but every uri is already parsed // once anyway to check if it is an encoded JSON uri, so this has negligible effect // on performance. if (lookupUri != null && !UriUtils.isEncodedContactUri(lookupUri)) { final List<String> segments = lookupUri.getPathSegments(); // This returns the third path segment of the uri, where the lookup key is located. // See {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. return (segments.size() < 3) ? null : Uri.encode(segments.get(2)); } else { return null; } } }
if (info != null && UriUtils.isEncodedContactUri(info.lookupUri)) { createNewContactButtonView.setTag(IntentProvider.getAddContactIntentProvider( info.lookupUri, info.name, info.number, info.type, true /* isNewContact */));