【问题标题】:Xamarin Essentials Android Contacts: is there a way to determine which phone number? EG: Home, Work, Mobile?Xamarin Essentials Android 联系人:有没有办法确定哪个电话号码?例如:家庭、工作、手机?
【发布时间】:2021-07-06 08:15:25
【问题描述】:
Xamarin Essentials 联系人:有没有办法确定哪个电话号码是哪个?例如:家庭、工作、移动设备?
这仅适用于 Android。
目前它只有电话号码,但我只需要显示 Mobile 电话号码(用于 SMS),我无法确定是否有号码被标记为“移动”。就像您在安卓手机上创建联系人一样,您可以将电话号码设置为家庭、手机、工作等。
或者任何人都知道另一个图书馆这样做?谢谢。
【问题讨论】:
标签:
xamarin
xamarin.forms
xamarin.android
【解决方案1】:
让我们以docs 为例。您可以使用枚举类型ContactType 的属性ContactType,但它只定义Unknown、Personal 和Work 值:
try
{
var contact = await Contacts.PickContactAsync();
if(contact == null)
return;
var phones = contact.Phones; // List of phone numbers
foreach (var phone in phones)
{
if (phone.ContactType == ContactType.Personal || phone.ContactType == ContactType.Work) //just an example
}
}
catch (Exception ex)
{
// Handle exception here.
}