Search code examples
androidandroid-intentphone-numberphone-calltel

Android make a call with "#" on the end


I found this code in this forum but i have the problem that i can’t use this char (# or /u0023) in the phone number.

I know that this question was already asked but you may know the App "Go SMS Pro" and this app can actually call this number. Now I want to ask you whether you know how to manage it.

try {
     Intent callIntent = new Intent(Intent.ACTION_CALL);
     String number = "tel:*100#"; /This is the number
     callIntent.setData(Uri.parse(asd));
     startActivity(callIntent);

     TelephonyManager tManager = (TelephonyManager) 
     getSystemService(Context.TELEPHONY_SERVICE);
     PhoneStateListener listener = new PhoneStateListener();
     tManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
} catch (ActivityNotFoundException activityException) {
     Log.e("telephony-example", "Call failed", activityException);
}

Solution

  • Url encode it.

    String number = "tel:*100%23";
    callIntent.setData(Uri.parse(asd));
    

    Or if you need a more general approach (like if you numbers change...) - encode the data part of the URI with a URLEncoder.

    String number = "tel:"+ URLEncoder.encode("*100#");
    ....