Fix contact lookup from number (old + new)

This commit is contained in:
Guillaume Beraudo 2011-10-05 15:13:15 +02:00
parent 491a71e017
commit f4466f78fc
2 changed files with 9 additions and 0 deletions

View file

@ -268,6 +268,10 @@ public class ContactPickerActivityNew extends AbstractContactPickerActivity {
// Finally using phone number
String normalizedNumber = PhoneNumberUtils.getStrippedReversed(username);
if (TextUtils.isEmpty(normalizedNumber)) {
// non phone username
return null;
}
Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(username));
projection = new String[]{PhoneLookup._ID, PhoneLookup.NUMBER};
c = resolver.query(lookupUri, projection, null, null, null);

View file

@ -29,6 +29,7 @@ import android.provider.Contacts;
import android.provider.Contacts.People;
import android.provider.Contacts.Photos;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
@SuppressWarnings("deprecation")
public class ContactPickerActivityOld extends Activity {
@ -120,6 +121,10 @@ public class ContactPickerActivityOld extends Activity {
public static Uri findUriPictureOfContact(ContentResolver resolver, String username, String domain) {
String normalizedNumber = PhoneNumberUtils.getStrippedReversed(username);
if (TextUtils.isEmpty(normalizedNumber)) {
// non phone username
return null;
}
String[] projection = {Contacts.Phones.PERSON_ID};
String selection = Contacts.Phones.NUMBER_KEY + "=" + normalizedNumber;
Cursor c = resolver.query(Contacts.Phones.CONTENT_URI, projection, selection, null, null);