diff options
Diffstat (limited to 'src/com/android/contacts/common/util/UriUtils.java')
-rw-r--r-- | src/com/android/contacts/common/util/UriUtils.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/com/android/contacts/common/util/UriUtils.java b/src/com/android/contacts/common/util/UriUtils.java index 1ede5f3a..41ef62f6 100644 --- a/src/com/android/contacts/common/util/UriUtils.java +++ b/src/com/android/contacts/common/util/UriUtils.java @@ -19,6 +19,8 @@ package com.android.contacts.common.util; import android.net.Uri; import android.provider.ContactsContract; +import java.util.List; + /** * Utility methods for dealing with URIs. */ @@ -71,4 +73,22 @@ public class UriUtils { } return ContactsContract.AUTHORITY.equals(uri.getAuthority()) ? uri : null; } + + /** + * 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; + } + } } |