Sending USSD code with alphabetic characters
Asked Answered
N

1

2

In my android app, I am sending USSD codes (#144#73#) using below Intent :

String baseUssd = Uri.encode("#") + "144" + Uri.encode("#");
StringBuilder builder = new StringBuilder();
builder.append(baseUssd);
builder.append("73");
builder.append(Uri.encode("#"));

Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + builder.toString()));

It's working well.

What I want now is to send this code :

#144#73MA#

I run this using the dial pad, following the Operator USSD menu, that worked. But if I try to do this programmatically using the above Intent that didn't work.

I know that alphabetic characters can't be used when typing code with the Dial Pad, but I though that It can be possible programmatically !!

Any Idea please !

Edit

When I try to send this programmatically : #144#73MA# I noticed that the Dialer application changes the alphabetic characters to their corresponding digit in the dial pad. Meaning that the dialer transform this : #144#73MA#

to this #144#7362# : why ?

Because :

  • the M matches the digit 6
  • the A matches the digit 2
Nucleus answered 1/4, 2014 at 11:18 Comment(3)
using the above Intent that didn't work --- Please define how exactly it did not work.Hanger
Thanks @shoerat, Happy to see your comment ! Let me edit my answer.Nucleus
Did you find a solution to this?Allege
H
6

Meaning that the dialer transform this : #144#73MA#

to this #144#7362# : why ?

I will try to answer only the why part.

Intent.ACTION_CALL is handled by OutgoingCallBroadcaster class. If you look at processIntent() method, there is this piece of code (lines 438~448 as of this writing):

String number = PhoneNumberUtils.getNumberFromIntent(intent, this);
// Check the number, don't convert for sip uri
// TODO put uriNumber under PhoneNumberUtils
if (number != null) {
    if (!PhoneNumberUtils.isUriNumber(number)) {
        number = PhoneNumberUtils.convertKeypadLettersToDigits(number);
        number = PhoneNumberUtils.stripSeparators(number);
    }
} else {
    Log.w(TAG, "The number obtained from Intent is null.");
}

There PhoneNumberUtils.convertKeypadLettersToDigits() converts the letters into the equivalent numeric digits:

public static String convertKeypadLettersToDigits (String input)

Translates any alphabetic letters (i.e. [A-Za-z]) in the specified phone number into the equivalent numeric digits, according to the phone keypad letter mapping described in ITU E.161 and ISO/IEC 9995-8.

Returns
the input string, with alpha letters converted to numeric digits using the phone keypad letter mapping. For example, an input of "1-800-GOOG-411" will return "1-800-4664-411".

Hope this helps.

Hanger answered 8/4, 2014 at 11:31 Comment(3)
Thanks, it's very helpful ! But just tell me please, is it possible to change this behaviour ? by overriding the OutgoingCallBroadcaster method or something like that ?!Nucleus
I don't see how that could be achieved unless if you can use other special characters instead of alphabetic letters; e.g., ~& instead of MAHanger
Unfortunately I can't. I am making an app to use USSD codes of operators. I can't change the codes !Nucleus

© 2022 - 2024 — McMap. All rights reserved.