Search code examples
win-universal-appwindows-10-mobileuwp-xaml

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


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?


Solution

  • 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.