Whether SIM card is available or not in windows ph

2019-07-25 02:45发布

问题:

I'm creating winrt universal project for mobile and tablet.

I want to check:

In mobile application, I am sending a sms text to sms application like this.

var message = new ChatMessage();
message.Recipients.Add("9999");
message.Body = "R*" + voucherNo + "*" + accountNo + "*" + pin;
await ChatMessageManager.ShowComposeSmsMessageAsync(message);

I want to place a check above that whether user has inserted sim card or using mobile with out sim card. Well app is not crashing due to this so this is not a big issue if I couldn't place that check here (as I have already searched alot about it but got nothing so I'm assuming that it is not possible right not in winrt to check sim card availability), but a link of documentation/blog/SO question regarding this where it is mentioned that you can't check sim card availability would be helpful.

Thanks.

回答1:

bool simAvailable = false;
var device = await ChatMessageManager.GetTransportsAsync();
if (device != null && device.Count > 0)
{
    foreach (var item in device)
    {
        if (item.TransportFriendlyName != "No SIM")
        {
            simAvailable = true;
            break;
        }
    }
}

Just enter this code and Simavailable will be true if phone hase sim card.