From f28ca902ad07ca3cf9c2f2e5d2d20dd58c0f13e5 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Sat, 8 Aug 2009 18:25:45 -0700 Subject: [PATCH] Update getNumberFromIntent() to read from both providers. This method is used by the Phone app to decode ACTION_CALL Intents, resolving to a real phone number. Because the columns are changing with the new provider, I added logic to query using the correct columns for the authority of the requested Uri. --- .../android/telephony/PhoneNumberUtils.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java index 4ed0a5c6198a6..a877c738b7268 100644 --- a/telephony/java/android/telephony/PhoneNumberUtils.java +++ b/telephony/java/android/telephony/PhoneNumberUtils.java @@ -22,6 +22,7 @@ import android.database.Cursor; import android.net.Uri; import android.os.SystemProperties; import android.provider.Contacts; +import android.provider.ContactsContract; import android.text.Editable; import android.text.SpannableStringBuilder; import android.text.TextUtils; @@ -129,15 +130,23 @@ public class PhoneNumberUtils } String type = intent.resolveType(context); + String phoneColumn = null; - Cursor c = context.getContentResolver().query( - uri, new String[]{ Contacts.People.Phones.NUMBER }, - null, null, null); + // Correctly read out the phone entry based on requested provider + final String authority = uri.getAuthority(); + if (Contacts.AUTHORITY.equals(authority)) { + phoneColumn = Contacts.People.Phones.NUMBER; + } else if (ContactsContract.AUTHORITY.equals(authority)) { + phoneColumn = ContactsContract.CommonDataKinds.Phone.NUMBER; + } + + final Cursor c = context.getContentResolver().query(uri, new String[] { + phoneColumn + }, null, null, null); if (c != null) { try { if (c.moveToFirst()) { - number = c.getString( - c.getColumnIndex(Contacts.People.Phones.NUMBER)); + number = c.getString(c.getColumnIndex(phoneColumn)); } } finally { c.close();