1

I’m unable to dial or call a string containing alphabets in android.

For Example: I want to dial a string *123*abcd#.

Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:"+"*123*abcd#")); //This string is not getting dialed 
                try
                {

                    startActivity(callIntent);
                }
                catch (android.content.ActivityNotFoundException ex)
{
                    Toast.makeText(getApplicationContext(),"yourActivity is not founded",Toast.LENGTH_SHORT).show();
                }

String *123*abcd# is not getting dialed or called. Please help to solve the same.

Soham
  • 4,397
  • 11
  • 43
  • 71
Gurpreet
  • 27
  • 4

2 Answers2

1
String s = "*123*abcd#";
if ((s.startsWith("*")) && (s.endsWith("#"))) {
    callstring = s.substring(0, s.length() - 1);
    callstring = callstring + Uri.encode("#");
} 
Intent i = new Intent(android.content.Intent.ACTION_CALL, Uri.parse("tel:" + callstring));
startActivity(i);

your need to encode the # before using it above code will do the trick.

Sahil Manchanda
  • 9,812
  • 4
  • 39
  • 89
0

To use Intent.ACTION_CALL you need to add Permission <uses-permission android:name="android.permission.CALL_PHONE"/> and since its a Dangerous permission you need to handle it Runtime for Android 6 and above.

You can rather use Intent.ACTION_DIAL which doesnt require any permission and will open the Phone app with the given number typed already, the user has to initiate the call.

Here is how to achieve this.

Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:*123*abcd#"));
startActivity(intent);
SanthoshN
  • 619
  • 3
  • 15
  • This doesnt solve the purpose, as it will dial only *123* as abcd and # will get omitted. is there any way to get abcd dialed in handset from app – Gurpreet Oct 14 '16 at 06:14