sending USSD code Android
Asked Answered
R

2

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

Roberson answered 22/6, 2012 at 14:7 Comment(0)
S
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);
        }
    });
Springy answered 11/7, 2015 at 8:27 Comment(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.Anarchist
Fair point :) I was just suggesting the "*" might nee to be encoded.Springy
F
0

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

Fatigue answered 3/10, 2020 at 4:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.