你怎么知道UWP设备是否有聊天/短信可用?

时间:2016-11-10 03:00:59

标签: c# windows-store-apps uwp

是否有一种C#方法可以调用以查看Windows10设备上的聊天/短信是否可用?

2 个答案:

答案 0 :(得分:0)

即使在没有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;

答案 1 :(得分:0)

您可以尝试:

if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.ApplicationModel.Chat "))
{     

}

仅当方法返回“true”时,才会实现其中的代码,这表示此设备中有SMS / Chat。

否则,您的项目将跳过此部分代码,因为如果您的应用可能会在这些设备上崩溃,设备中的功能将无法使用。

有关详细信息,请查看this document

相关问题