2016-11-10 60 views

回答

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

你可以试试:

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

} 

只有当方法返回“true”时,它内部的代码才会被执行,这表明SMS/Chat在这个设备中可用。

否则,您的项目将跳过这部分代码,因为设备中的功能不可用,以防您的应用在这些设备上崩溃。

欲了解更多详情,可能会检查this document

相关问题