How to make a ussd request in a Xamarin crossplatform app without opening the dialer

I want to make a USSD call in a xamarin.android using C# and i have no idea where to start. All the examples i have seen is done in java. Is it possible to successfully dial a USSD code like *270# within my app without opening the dialer? If yes, please how? I just need a solution for the xamarin.android part. I'll be very grateful for any help

Answers

  • izhangizhang USMember, Xamarin Team Xamurai

    This should be possible by creating a URI starting with "tel:" and then adding to it your USSD code as a character. This then can be converted to a Android.Net.Uri which is passed into the ACTION_CALL intent.

    Example code to create the URI:
    private Android.Net.Uri createUriFromString(String ussd){<br /> String uri = "tel:";<br /> foreach(char c in ussd.ToCharArray()){<br /> if(c == '#'){<br /> uri += Android.Net.Uri.Decode("#");<br /> }else{<br /> uri += c;<br /> }<br /> }<br /> return Android.Net.Uri.Parse(uri);<br /> }

    Using the ACTION_CALL intent:
    var intent = new Intent(Intent.ActionCall, createUriFromString("*270#"));
    StartActivity(intent);

  • jocodesjocodes Member ✭✭

    Thank you this worked for me after changing Decode to Encode

Sign In or Register to comment.