0

hi guys i am making an app in which when user click on button it will redirect them to phone app of android with *700# entered. but the problem is when i write # in string it doesn't appear in phone app of android.

here is the code:

public void activite (View view) {
        String number = "*700#";
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:" +number));
        startActivity(intent);
    }

it works fine except that number sign doesn't come up please help.

Murtaza
  • 61
  • 8

3 Answers3

2

Try this method,

private Uri getCallString(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);
}

To call it,

String number = "*700#";
Intent intent = new Intent(Intent.ACTION_CALL, getCallString(number));
startActivity(intent);

See this SO thread.

Community
  • 1
  • 1
K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33
1

Try out this:

public void activite (View view) {
    String encodedHash = Uri.encode("#"); //encode hash here
    String number = "*700";
    Intent intent = new Intent(Intent.ACTION_DIAL);
    intent.setData(Uri.parse("tel:" +number+encodedHash)); //updated here
    startActivity(intent);
}
W4R10CK
  • 5,502
  • 2
  • 19
  • 30
0
 public void activite (View view) {
        String number = "*700";
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:" + Uri.encode( number + "#")));
        startActivity(intent);
    }

this is how it works for me. THANK YOU GUYS FOR REPLYING MY QUERY!

Murtaza
  • 61
  • 8