Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
390 views
in Technique[技术] by (71.8m points)

android - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...