Habib Mhamadi
Habib Mhamadi

Reputation: 769

How to parse a string in the URI that contains hash sign

I am having trouble with parsing a string that contains "#" in URI, I want to open Device Dial-Up and parse this string "*344*12*#" to it. the below code is my implementation and the problem is that I get the string without "#" in Dial-Up.

    @Override
public void onBindViewHolder(@NonNull RecyclerAdapterDataView holder, int i) {

    final String code = list.get(i).getActivation();
    holder.activation.setText("Activation Code:  "+code);

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

            if (code.contains("#")){
                Intent i = new Intent();
                i.setAction(Intent.ACTION_DIAL);
                i.setData(Uri.parse("tel:"+code));
                context.startActivity(i);
            }
        }
    });
}

Upvotes: 1

Views: 209

Answers (1)

Omkar
Omkar

Reputation: 3100

try below code this may help

        if (code.contains("#")){
            Intent i = new Intent();
            i.setAction(Intent.ACTION_DIAL);
            i.setData(Uri.parse("tel:"+Uri.encode(code))); //here add Uri.encode
            context.startActivity(i);
        }

Upvotes: 1

Related Questions