gpt4 book ai didi

android - 在Android中按类型获取电话号码

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:40:22 24 4
gpt4 key购买 nike

我想根据类型检索所选联系人的电话号码。我想打印电话号码类型和关联的电话号码。

我可以显示所选联系人的电话号码,但无法区分类型。

下面是我使用的示例代码:

if (Integer.parseInt(cursor.getString(
cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor phoneCursor = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
new String[]{contactId,}, null
);
while (phoneCursor.moveToNext()) {
// Do something with phones
System.out.println("phone numbers :"
+ phoneCursor.getString(
phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)
)
);
}
phoneCursor.close();
}

最佳答案

以防万一您不想自己做,这里有一个类型列表,其中包含 android 允许的所有主要类型。

String sType = "";
switch (type) {
case Phone.TYPE_HOME:
sType = "Home";
break;
case Phone.TYPE_MOBILE:
sType = "Mobile";
break;
case Phone.TYPE_WORK:
sType = "Work";
break;
case Phone.TYPE_FAX_HOME:
sType = "Home Fax";
break;
case Phone.TYPE_FAX_WORK:
sType = "Work Fax";
break;
case Phone.TYPE_MAIN:
sType = "Main";
break;
case Phone.TYPE_OTHER:
sType = "Other";
break;
case Phone.TYPE_CUSTOM:
sType = "Custom";
break;
case Phone.TYPE_PAGER:
sType = "Pager";
break;
}

关于android - 在Android中按类型获取电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6579957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com