问题
I have a function to get all contacts with part of a phone number, here...
Cursor c = getContentResolver().query(Data.CONTENT_URI,
new String[] {Data._ID, Phone.NUMBER},
Phone.NUMBER + " like ?",
new String[] {"%"+String.valueOf(phoneNumber) +"%"}, null);
while (c.moveToNext()) {
String id = c.getString(0);
String number = c.getString(1);
Log.d("id",id);
Log.d("number",number);
}
but the problem is - IF i insert 31221 I can't get contacts with a phone number like 312-2131-321
Because of "-" or i if i insert 0558836298 i cant get +62558836298 because of "+" and country code.
Thanks for the help
PS I do know about
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
but that works only if you put the whole number.
回答1:
Please try to replace this:
Phone.NUMBER
with this:
"replace("+Phone.NUMBER+", '-','')"
It's using replace function from SQLite to remove hypens.
来源:https://stackoverflow.com/questions/17004281/hyphens-are-an-issue-in-getting-contact-details-with-a-partial-phone-number