Make USSD call in android

后端 未结 7 1028
南旧
南旧 2020-12-03 07:58

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 n

相关标签:
7条回答
  • 2020-12-03 08:38

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

    <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
    
    0 讨论(0)
  • 2020-12-03 08:40

    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);
    
    0 讨论(0)
  • 2020-12-03 08:48

    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" />
    
    0 讨论(0)
  • 2020-12-03 08:50

    You can 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);
    
    0 讨论(0)
  • 2020-12-03 08:51

    This works for me:

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

    Then in work code:

    Intent callIntent = new Intent(Intent.ACTION_CALL, ussdToCallableUri(yourUSSDCodeHere));
    startActivity(callIntent);
    
    0 讨论(0)
  • 2020-12-03 09:01
    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

    0 讨论(0)
提交回复
热议问题