UWP: How to send USSD request. (Get exception, when call SendMessageAndGetReplyAsync)

0

please help me with sending ussd request.

IReadOnlyList<string> networkAccIds = MobileBroadbandAccount.AvailableNetworkAccountIds;
if (networkAccIds.Count == 0)
{
    return;
}
string networkAccountId = networkAccIds[0];
UssdSession session = UssdSession.CreateFromNetworkAccountId(networkAccIds[0]);

2 sim card installed in my phone. But networkAccIds.Count always zero. What's my mistake?

update 1:

Thanks Jerry Li. I got the network identifiers. I have a new problem. When I do:

UssdReply reply = await session.SendMessageAndGetReplyAsync(new UssdMessage("*100#")); 

I get exception:

Unexpected exception occured: System.Runtime.InteropServices.COMException (0x80070032): The request is not supported.

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()


   at uwp_1.MainPage.<GetBalance>d__1.MoveNext()

Why do I get exception?

win-universal-app
windows-10-mobile
uwp-xaml
asked on Stack Overflow May 8, 2016 by (unknown user) • edited May 23, 2017 by Community

1 Answer

0

2 sim card installed in my phone. But networkAccIds.Count always zero. What's my mistake?

You are accessing privileged APIs (UssdSession and MobileBroadbandAccount) used by mobile broadband operators. It requires a special-use capability to be declared in package manifest:

<Capabilities>
  <r:Capability Name="cellularDeviceIdentity"/>
  <r:Capability Name="cellularDeviceControl"/>
  <r:Capability Name="cellularMessaging"/>
</Capabilities>

Please make sure you have declared the corresponding special-use capabilities in package manifest. And the Mobile broadband sample which shows how to use the Mobile Broadband Networking API is for your reference.

In addition:

Your app will work and you can test it on your phone, but it will not pass WACK (Windows App Certification Kit) because it uses a special-use capability. This kind of apps can be used in Company app(Don’t need to publish to Windows Store), MS internal or OEM/partner.

answered on Stack Overflow May 9, 2016 by Jerry Li

User contributions licensed under CC BY-SA 3.0