WP 8.1运行时代码,用于拨打电话,发送短信&发送电子邮件(不是Silverlight 8.1)

时间:2014-05-22 03:55:31

标签: c# windows-phone-8.1 windows-phone sms phone-call

我正在编写一个应用程序,可以拨打电话,发送短信或电子邮件,就像wp 8.1中的People应用程序一样。 到目前为止,我已经找到一个msdn的链接表单,其中说“适用于:Windows Phone 8和Windows Phone Silverlight 8.1”。 所以代码在这里:from this link

using Microsoft.Phone.Tasks;

private void TextBlock_Tapped_Call(object sender, TappedRoutedEventArgs e)
{
    PhoneCallTask phoneCallTask = new PhoneCallTask();
    phoneCallTask.PhoneNumber = "2065550123";
    phoneCallTask.DisplayName = "Gage";

    phoneCallTask.Show();
}

但我收到了一个错误:

名称空间“Microsoft”中不存在类型或命名空间名称“Phone”(您是否缺少程序集引用?)

编辑:很抱歉有一个重复的问题,同样在这里:Make a phone call in Windows Phone 8.1 回答@Chris Shao,他还更新了发送短信和电子邮件的代码。

1 个答案:

答案 0 :(得分:36)

如果您要使用Microsoft.Phone.Tasks,则必须创建 Windows Phone Silverlight 8.1 项目。如果您的项目是 Windows Phone 8.1

您可以使用此代码拨打电话:

Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI("phone number", "display name");

并使用它来发送短信:

Windows.ApplicationModel.Chat.ChatMessage msg = new Windows.ApplicationModel.Chat.ChatMessage();
msg.Body = "This is body of demo message.";
msg.Recipients.Add("10086");
msg.Recipients.Add("10010");
await Windows.ApplicationModel.Chat.ChatMessageManager.ShowComposeSmsMessageAsync(msg);

并使用它来发送邮件:

Windows.ApplicationModel.Email.EmailMessage mail = new Windows.ApplicationModel.Email.EmailMessage();
mail.Subject = "This is Subject";
mail.Body = "This is body of demo mail";
mail.To.Add(new Windows.ApplicationModel.Email.EmailRecipient("shaom_wp@hotmail.com", "shaomeng"));
await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(mail);