Android HAS_PHONE_NUMBER
我正在尝试编写一种方法来确定联系人是否至少有一个电话号码,目前我有这样的情况:
public boolean hasPhone() {
Cursor phones = this.map.getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI,
null,
ContactsContract.Contacts._ID + "=" + this.contactId,
null,
null
);
boolean has = false;
if(phones.moveToFirst()) {
do {
if(Integer.parseInt(phones.getString(phones.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
has = true;
break;
}
} while(phones.moveToNext());
}
return has;
}
该方法总是返回 false,即使我知道相关联系人有电话号码。我也知道 contactId 是正确的,因为我也用它来获取邮政地址等。
任何帮助将不胜感激,因为我快要抓狂了:p
谢谢。
I am trying to write a method that determines if a contact has at least one phone number, at the moment I have this:
public boolean hasPhone() {
Cursor phones = this.map.getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI,
null,
ContactsContract.Contacts._ID + "=" + this.contactId,
null,
null
);
boolean has = false;
if(phones.moveToFirst()) {
do {
if(Integer.parseInt(phones.getString(phones.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
has = true;
break;
}
} while(phones.moveToNext());
}
return has;
}
the method always returns false, even though I know the contact in question has a phone number. Also I know the contactId is correct as I also use it to get the postal address, etc.
Any help would be greatly appreciated, as I am about to tear my hair out :p
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个。将以下行替换
为这一行
看看是否有效。
Try this. Replace the following line
with this line
See if that works.