Home » Android » How to make a phone call programmatically?

How to make a phone call programmatically?

Posted by: admin November 29, 2017 Leave a comment

Questions:

i’m passing to an activity the number to call by a bundle

and then, in such activity, i have a button to call to that number, this is the code:

callButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(bundle.getString("mobilePhone")));
            }
        }); 

something is wrong, because when i press the button nothing happens…

what i am doing wrong?

PD: i’m using Android 1.5 compatible project… maybe phone call is incompatible to 1.5?

Answers:

You forgot to call startActivity. It should look like this:

Intent intent = new Intent(Intent.ACTION_CALL);

intent.setData(Uri.parse("tel:" + bundle.getString("mobilePhone")));
context.startActivity(intent);

An intent by itself is simply an object that describes something. It doesn’t do anything.

Don’t forget to add the relevant permission to your manifest:

<uses-permission android:name="android.permission.CALL_PHONE" />

Questions:
Answers:

Tried this on my phone and it works perfectly.

Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:900..." ));
startActivity(intent);

Add this permission in manifest file.

<uses-permission android:name="android.permission.CALL_PHONE" />

Questions:
Answers:
 Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+198+","+1+","+1)); 
             startActivity(callIntent);

for multiple ordered call

This is used to DTMF calling systems.
If call is drop then, you should pass more ” , ” between numbers.

Questions:
Answers:

Take a look there : http://developer.android.com/guide/topics/intents/intents-filters.html

DO you have update your manifest file in order to give call rights ?

Questions:
Answers:

Here I will show you that how you can make a phone call from your activity. To make a call you have to put down this code in your app.

try {
    Intent my_callIntent = new Intent(Intent.ACTION_CALL);
    my_callIntent.setData(Uri.parse("tel:"+phn_no));
    //here the word 'tel' is important for making a call...
    startActivity(my_callIntent);
} catch (ActivityNotFoundException e) {
    Toast.makeText(getApplicationContext(), "Error in your phone call"+e.getMessage(), Toast.LENGTH_LONG).show();
}

Questions:
Answers:

In the selected answer, there is not check for marshmallow permission.
It will not work directly in marshmallow 6.0 or above device.

I know I am too late but this question has large vote so I thought it will help to others in future.

In marshmallow devices we need to take run time permission for call…

Here is example to make call in marshmallow or above.

How to make call in android marshmallow 6.0 or above

Questions:
Answers:
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); 
   final Button button = (Button) findViewById(R.id.btn_call);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String mobileNo = "911";
            String uri = "tel:" + mobileNo.trim();
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse(uri));
            startActivity(intent);
        }
    });*
 }