我使用下面的代码从给定编号中从数据库获取编号,为此我在查询下面触发以获取编号,但它不返回编号。我的查询中有问题吗?请帮助我解决此问题。
我需要使用LIKE函数,因为一些数字用特殊的字符和空格存储。
contactNumber = contactNumber.replaceAll("[-+.^:,]", "");
contactNumber="%"+contactNumber+"%";
String strEmail = "";
String name = "";
Cursor cursor = ctx.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.NUMBER + " LIKE ?", new String[]{contactNumber}, null);
这是使用ContentProvider时使用LIKE的方法:
getContentResolver().query(Phone.CONTENT_URI, null, Phone.NUMBER + " LIKE ?", new String[] { "%" + contactNumber + "%" }, null);
但是,通过电话号码搜索的最佳方法是使用专用的PhoneLookup
API:
PhoneLookup
都经过优化,可以更快地返回结果,并且可以处理带或不带国家或地区代码的电话号码。