4

I'm trying to send a USSD code through my cellphone, so I used an intent as many here suggested is the way to send the code. Unfortunately, every time I send the code it sends the same number *4355696753

the code I'm using to send the USSD is:

sendCode.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String cUssd = ussdCodeEdTxt.getText().toString();
            String cToSend = "tel:*" + cUssd + Uri.encode("#");
            startActivityForResult(new Intent("android.intent.action.CALL",
                       Uri.parse(cToSend)), 1);

        }
    });

any ideas would be greatly appreciated

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
Pedro Teran
  • 1,200
  • 3
  • 17
  • 43

2 Answers2

2

I think you may need to use Uri.encode("*") for the star as well

sendCode.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String cUssd = ussdCodeEdTxt.getText().toString();
            String cToSend = "tel:" + Uri.encode("*") + cUssd + Uri.encode("#");
            startActivityForResult(new Intent("android.intent.action.CALL",
                       Uri.parse(cToSend)), 1);
        }
    });
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
formica
  • 934
  • 1
  • 8
  • 16
  • 2
    There is no use calling startActivityForResult instead of startActivity. You can simply call startActivity, as USSD call doesn't return any result to the calling activity. If you wanna read the content of the returned text, see this [link](http://umeshisran4android.blogspot.com/2015/11/how-to-readparse-ussd-messages.html). – Merhawi Fissehaye Nov 05 '16 at 13:26
  • Fair point :) I was just suggesting the "*" might nee to be encoded. – formica Nov 06 '16 at 19:28
0

though this is an old post but, for those facing the same issue try this Uri.fromParts("tel", number eg = *222# , "#");