Make USSD call in android

2019-01-14 18:34发布

To check the balance first i have to make a call *xxx# and then i get a response with the multiple options to choose from and after i input the particular number i get the balance.

What code can i use for the same in my android app?

Dialing *xxx*x# is giving me error.

Below is my code which works fine for the *xxx# calls:

String encodedHash = Uri.encode("#");
String ussd = "*" + encodedHash + lCallNum + encodedHash;
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussd)));

标签: android ussd
7条回答
手持菜刀,她持情操
2楼-- · 2019-01-14 18:42

Important thing to remember :

If your are targeting Android Marshmallow (6.0) or higher then you need to request Manifest.permission.CALL_PHONE permission at runtime

查看更多
Ridiculous、
3楼-- · 2019-01-14 18:43

Use this code, it works

Intent callIntent = new Intent(Intent.ACTION_CALL);
            String ussdCode = "*" + 2 + Uri.encode("#");
            callIntent.setData(Uri.parse("tel:" +ussdCode));

            if (ActivityCompat.checkSelfPermission(MainActivity.this,
                    Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            startActivity(callIntent);

Add this line in Manifest file too

<uses-permission android:name="android.permission.CALL_PHONE" />
查看更多
Luminary・发光体
4楼-- · 2019-01-14 18:47

Don't forget to add permission it will solve skype problem:P

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
查看更多
Deceive 欺骗
5楼-- · 2019-01-14 18:50
String ussd = "*XXX*X" + Uri.encode("#");
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussd)));

this works perfect with me. just place the first bunch as it is then encode the # to make it have a complete *XXX*X#. this will definitely be of help

查看更多
甜甜的少女心
6楼-- · 2019-01-14 18:54

Try this, I did not test it, but should work.

Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Uri.encode("*3282#")));
startActivity(intent);
查看更多
Juvenile、少年°
7楼-- · 2019-01-14 18:55

Use this code. It works for me:

Intent intent = new Intent(Intent.ACTION_CALL);
    intent.setData(Uri.parse(Uri.parse("tel:" + "*947")+Uri.encode("#")));
    startActivity(intent);
查看更多
登录 后发表回答