hyphens are an issue in getting contact details with a partial phone number

依然范特西╮ 提交于 2019-12-11 11:16:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!