Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

c# - WP 8.1 Runtime code to make phone call, send SMS & send Email (not the Silverlight 8.1)

I'm writing an app which will make a phone call, send sms or email just like the People app in wp 8.1 . So far I've found a link form msdn which said "Applies to: Windows Phone 8 and Windows Phone Silverlight 8.1". So here the code: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();
}

But I got an error:

The type or namespace name 'Phone' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Edit: Sorry for a duplicate question, same here: Make a phone call in Windows Phone 8.1 Answer by @Chris Shao, he also updated code to send SMS and Email.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want to use Microsoft.Phone.Tasks, you must create Windows Phone Silverlight 8.1 project. And if your project is Windows Phone 8.1,

you can use this code to phone call:

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

and use this to send sms:

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);

and use this to send mail:

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...