Get SIM MSISDN & IMSI number in Windows Phone Appl

2019-08-21 07:02发布

问题:

Is it possible to get the SIM MSISDN & IMSI number in windows Phone app development?

I have gone through some of the Q/A but they all are asked a long time ago.

回答1:

You could get SIM MSISDN & IMSI number in Windows Phone Application. Please notice that you should manually edit your application Package.appxmanifest as follows:

<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" 
    xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
    xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
    xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
    IgnorableNamespaces="uap mp rescap">

......

<Capabilities>
    <rescap:Capability Name="cellularDeviceIdentity" />
</Capabilities>

The cellularDeviceIdentity capability allows apps to access cellular identification data. Anyone may request access to these capabilities for store submission.

You could use MobileBroadbandModem class to get all CurrentDeviceInformation, and the following is core codes.

using Windows.Networking.NetworkOperators;

......

public IReadOnlyList<SimCard> GetSimCards()
{
    var results = new List<SimCard>();

    var modem = MobileBroadbandModem.GetDefault();
    if (modem == null)
    {
        return results.AsReadOnly();
    }

    var account = modem.CurrentAccount;
    if (account == null)
    {
        return results.AsReadOnly();
    }
    var simCard = new SimCard();
    simCard.ICCID = account.CurrentDeviceInformation.SimIccId;
    simCard.IMSI = account.CurrentDeviceInformation.SubscriberId;
    simCard.MSISDN = modem.DeviceInformation.TelephoneNumbers;

    simCard.MCC = ExtractMCC(simCard.IMSI);
    simCard.MNC = ExtractMNC(simCard.IMSI);
    simCard.MSID = ExtractMSID(simCard.IMSI);

    results.Add(simCard);

    return results.AsReadOnly();
}

I have uploaded code sample to git hub. Please check!