13

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)));
4

7 回答 7

23

这对我有用:

private Uri ussdToCallableUri(String ussd) {

    String uriString = "";

    if(!ussd.startsWith("tel:"))
        uriString += "tel:";

    for(char c : ussd.toCharArray()) {

        if(c == '#')
            uriString += Uri.encode("#");
        else
            uriString += c;
    }

    return Uri.parse(uriString);
}

然后在工作代码中:

Intent callIntent = new Intent(Intent.ACTION_CALL, ussdToCallableUri(yourUSSDCodeHere));
startActivity(callIntent);
于 2014-02-26T14:34:41.343 回答
8

不要忘记添加权限它将解决Skype问题:P

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
于 2015-09-09T04:38:48.653 回答
5
String ussd = "*XXX*X" + Uri.encode("#");
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussd)));

这对我来说很完美。只需放置第一束,然后对其进行编码#以使其具有完整的*XXX*X#. 这肯定会有所帮助

于 2015-06-17T23:29:52.037 回答
4

要记住的重要事项:

如果您的目标是Android Marshmallow (6.0)或更高版本,那么您需要在运行时请求Manifest.permission.CALL_PHONE权限

于 2017-02-10T05:52:01.443 回答
3

试试这个,我没有测试它,但应该可以。

Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Uri.encode("*3282#")));
startActivity(intent);
于 2017-05-30T20:20:51.317 回答
2

您可以使用此代码。这个对我有用:

Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(Uri.parse("tel:" + "*947") + Uri.encode("#")));
startActivity(intent);
于 2015-10-17T10:56:14.437 回答
1

使用此代码,它可以工作

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);

在 Manifest 文件中添加这一行

<uses-permission android:name="android.permission.CALL_PHONE" />
于 2016-12-06T06:30:44.713 回答