Unfortunately, these capabilities are only available to mobile operator apps or apps given special privilege from mobile operators. Please see the note below the code.
In Windows 10:
The API you are looking for is Windows.Networking.NetworkOperators.MobileBroadbandAccount
private string GetSubscriberId()
{
MobileBroadbandAccount mbaAccount = null;
var modem = MobileBroadbandModem.GetDefault();
mbaAccount = modem.CurrentAccount;
return mbaAccount.CurrentDeviceInformation.SimIccId;
}
Link to documentation:
https://learn.microsoft.com/en-us/uwp/api/Windows.Networking.NetworkOperators.MobileBroadbandAccount
You will need to modify your Package.appxmanifest file like mentioned below (more info on restricted capabilities)
<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 wincap rescap">
....
....
....
....
<Capabilities>
<r:Capability Name="cellularDeviceIdentity" />
<r:Capability Name="cellularDeviceControl" />
<r:Capability Name="cellularMessaging" />
</Capabilities>
</Package>
NOTE: If your application targets Windows 10, this should not be a problem if you are going to side load the application. As you can install any app which requires special privilege once you enable Developer Mode or Sideloading on your device from settings.
In case the access is critical to you application and you want to publish it to Windows Store you can try contacting Microsoft to give your account required special privilege.
In Windows Phone 8.1:
As mentioned above the capability is restricted and the API for WP8.1 and below are only shared with mobile partners and you can't sideload or publish these applications until and unless you have been given special access by Microsoft.