How do I show the # character with this string on dialer when I click on check button?

54 views Asked by At

My dialer is just showing "*16001":

 private Button checksim;
    private String number = "*16001#";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bangladeshsimverification);

        checksim = findViewById(R.id.b_b_check);
        checksim.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent opendialer = new Intent(Intent.ACTION_DIAL);
                opendialer.setData(Uri.parse("tel:" + number));
                if (opendialer.resolveActivity(getPackageManager()) != null) {
                    startActivity(opendialer);
                }
            }
        });

    }

I want to add '#' at the end of this string, but it is not working. How can I achieve this?

1

There are 1 answers

0
Imranur Rahman On

For your case, Uri.parse method cannot handle special character like '#'. A simple way around is to encode the string with proper formatting before using Uri.parse.

For example, try using:

URLEncoder.encode(value, StandardCharsets.UTF_8.toString());