Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a USSD code containing decimal floating point (.)?

I need to send a USSD code containing a double value, that represents the balance account amount to be transferred. This value is composed by an integer number, and optionally a decimal separator and 2 more digits. My code looks as follows:

    double doubleValue = 0.70;
    String phoneNumber = "51234567", pincode = "1234";
    String ast = Uri.encode("*");
    String baseUssd = ast + "234" + ast + "1" + ast + phoneNumber + ast + pincode + ast;
    StringBuilder builder = new StringBuilder();
    builder.append(baseUssd);
    builder.append(doubleValue); //i.e: 1.35, 0.80
    builder.append(Uri.encode("#"));
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + builder.toString()));
    startActivity(intent);

My phone treats the doubleValue as 135, 080, etc. ignoring the dot separator character. I hope the final code includes "dot", allowing send the decimal value. Someone solved this problem?

like image 408
Roberto Tellez Ibarra Avatar asked Jul 02 '15 23:07

Roberto Tellez Ibarra


People also ask

How to USSD code?

USSD is a technology platform through which information can be transmitted through a GSM network on a basic phone. This service will be available on all mobile phones with SMS facility. To use USSD mobile banking, users will have to simply dial *99# and use the interactive menu.

How to run USSD code in android?

Running a USSD Code. Open the phone app. This app can be found on your home screen, on the "All Apps" screen, or, on simpler cell phones, on the lock screen. Dial the USSD code.

How many digits float data contains after decimal point?

Floats can represent decimal values up to 7 digits of precision, and double can represent decimal values up to 16 digits of precision. The single precision number format occupies 4 bytes, or 32 bits, in computer memory, while the double precision number format occupies 8 bytes, or 64 bits, in the memory of a computer.

What is a USSD code running mean?

USSD code running on your Android phone means that your phone is entered into the process to provide you with the information you want.


2 Answers

The Java code shown works fine of course assuming that doubleValue is a float or a double.

As suggested here the Intent is handled by OutgoingCallBroadcaster.processIntent() which processes the String given in the Intent by calling PhoneNumberUtils.convertKeypadLettersToDigits() and PhoneNumberUtils.stripSeparators().

The latter one strips everything except numbers, *, #, + and the WILD, WAIT and PAUSE symbols.

This is where your decimal separator is lost.

So either the separator should be escaped to a specific numerical value or substituted by one of the accepted symbols to actually leave your phone and reach the receiver.

Whoever is responsible for the receiving end can probably advice you on properly formatting your decimal number.

like image 188
Markus Kauppinen Avatar answered Oct 13 '22 05:10

Markus Kauppinen


Thinking about the way the pinpad, which my bank sent me, works, you always have to enter the two digits after the decimal point and the formatting on the display deals with the position of the point.

So if i enter "1", it is interpreted as 0.01. Similarly "1023" would be 10.23.

I think the same approach could work nicely for you. So 1.23 is entered as "123" and 0.80 as "80"

I can't see a reference that limits the characters to 0-9#* but all the examples follow this format. However, your example starts *234, which seems to fit this rule in the specification

Case a) 1, 2 or 3 digits from the set (*, #) followed by 1X(Y), where X=any number 0-4, Y=any number 0-9, then, optionally "* followed by any number of any characters", and concluding with # SEND: This case is reserved for HPLMN use. When a serving network receives such a message from a visiting subscriber, it shall pass the USSD message directly to the HPLMN. If it receives it from a home subscriber, it is up to the network to decide whether to treat it locally or to pass it to the HLR

http://www.etsi.org/deliver/etsi_ts/100600_100699/100625/07.00.00_60/ts_100625v070000p.pdf

In general, I am not sure the HPLMN (Home Public Land Mobile Network) or HLR (Home Location Register) would expect the extra characters, even though the whole character set and even other character sets are allowed in the USSD protocol.

like image 20
formica Avatar answered Oct 13 '22 06:10

formica