首页 > 代码库 > Windows Phone 8.1 联系人与日历

Windows Phone 8.1 联系人与日历

(1)联系人(Manifest 获取权限)

1)获取联系人

获取联系人的方式有两种

A. ContactPicker

ContactPicker 也就是直接打开一个系统的选择联系人界面,让用户选择,可设置单选或多选:

var contactPicker = new ContactPicker();

contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);

//Windows.ApplicationModel.Contacts.Contact contact = await contactPicker.PickContactsAsync();
Windows.ApplicationModel.Contacts.Contact contact = await contactPicker.PickContactAsync();
if( contact != null )
{
    MessageDialog dialog = new MessageDialog(string.Format("Phone Number: {0}", contact.Phones.First().Number), contact.DisplayName);
    await dialog.ShowAsync();
}

必须设置唯一的一个 ContactFieldType。

B. ContactManager

可通过 ContactManager API 直接搜索某联系人:

ContactStore contactStore = await ContactManager.RequestStoreAsync();
var list = await contactStore.FindContactsAsync(searchTextBox.Text.Trim());

获取的联系人列表为只读的。

2)与联系人联系

可直接向联系人拨打电话、发送短信、发送邮件:

PhoneCallManager.ShowPhoneCallUI("15911111111", "Some");

ChatMessage message = new ChatMessage();
message.Recipients.Add("15911111111");
message.Body = "Test.";
await ChatMessageManager.ShowComposeSmsMessageAsync(message);

EmailMessage email = new EmailMessage();
email.To.Add(new EmailRecipient("aaa@qq.com"));
email.Body = "Test.";
await EmailManager.ShowComposeNewEmailAsync(email);

 

(2)日历

1)直接打开系统的日历应用

比如打开日历主界面:

await AppointmentManager.ShowTimeFrameAsync(DateTimeOffset.Now, TimeSpan.FromHours(1));

 

2)API 方式

比如新建一个日历事件:

Appointment appointment = new Appointment();
appointment.Subject = "";
appointment.StartTime = DateTimeOffset.Now;
//...
await AppointmentManager.ShowAddAppointmentAsync(appointment, new Rect());

更多 API :链接