【发布时间】:2017-03-23 23:48:50
【问题描述】:
是否有 C# 方法可以调用以查看 Windows10 设备上是否可以使用 Chat/SMS?
【问题讨论】:
标签: c# windows-store-apps uwp
是否有 C# 方法可以调用以查看 Windows10 设备上是否可以使用 Chat/SMS?
【问题讨论】:
标签: c# windows-store-apps uwp
即使在没有 SIM 卡的设备上,您也可以使用聊天功能。甚至Skype也可以扮演默认短信应用的角色……
This link 给你一个样本
private async void ComposeSms(Windows.ApplicationModel.Contacts.Contact recipient, string messageBody, StorageFile attachmentFile, string mimeType)
{
var chatMessage = new Windows.ApplicationModel.Chat.ChatMessage();
chatMessage.Body = messageBody;
if (attachmentFile != null)
{
var stream = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(attachmentFile);
var attachment = new Windows.ApplicationModel.Chat.ChatMessageAttachment(mimeType, stream);
chatMessage.Attachments.Add(attachment);
}
var phone = recipient.Phones.FirstOrDefault<Windows.ApplicationModel.Contacts.ContactPhone>();
if (phone != null)
{
chatMessage.Recipients.Add(phone.Number);
}
await Windows.ApplicationModel.Chat.ChatMessageManager.ShowComposeSmsMessageAsync(chatMessage);
}
要检查消息是否为 SIM 消息,您应该查看属性 ChatMessage.IsSimMessage
var isSimMessage = chatMessage.isSimMessage;
【讨论】:
你可以试试:
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.ApplicationModel.Chat "))
{
}
只有当方法返回“true”时,它里面的代码才会被执行,这表明这个设备可以使用SMS/Chat。
否则,您的项目将跳过这部分代码,因为该功能在设备中不可用,以防您的应用在这些设备上崩溃。
更多详情可查看this document。
【讨论】: