【发布时间】:2014-11-11 07:00:00
【问题描述】:
在我的 android 应用程序中,当有来电时,我想显示我的自定义 ui 并且我能够做到这一点。 不,我想检查传入的号码是否来自联系人。 下面是我这样做的代码,但它为存储在我的联系人列表中的传入号码返回 null。
public String findNameByNumber(String num){
Uri uri = Uri.withAppendedPath(Phones.CONTENT_FILTER_URL, Uri.encode(num));
String name = null;
Cursor cursor = mContext.getContentResolver().query(uri,
new String[] { Phones.DISPLAY_NAME }, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
name = cursor.getString(cursor.getColumnIndex(Phones.DISPLAY_NAME));
cursor.close();
callyName.setText(name+" Calling..");
}
return name;
}
我有来自一个号码say+917878787878的来电,但在我的联系人中,此联系人存储为名称XYZ,号码为78 78 787878,这是因为号码之间有空格而形成的。也可以尝试排除+91但仍然它返回空值。 那么我怎样才能找到以任何格式存储的号码。可能与国家代码一起存储或不存储。
提前致谢。
【问题讨论】:
标签: android android-contentprovider