Android studio Action call to run USSD codes

Using the application, I want to run the USSD code, but the problem is that it does not recognize the "#" character. If I want to run "* 100 #", it only recognizes the input as "* 100". How to add "#". and what is the reason not to admit it?

Here is my code ...

  checkBalance.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent i = new Intent(Intent.ACTION_CALL);


            i.setData(Uri.parse("tel:"+"*100#"));

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



        }
    });
+4
source share
2 answers

Try this code. Use Uri.encode("#"):

    String encodedHash = Uri.encode("#");
    i.setData(Uri.parse("tel:"+"*100"+encodedHash));

    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    startActivity(i);
+2
source

You need to use Uri.encode("YOUR USSD CODE")at Uri.Parse().

Example:

Uri.parse("tel:"+ Uri.encode("*100#"));
+2
source

Source: https://habr.com/ru/post/1678678/


All Articles