137

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 am I doing wrong?

PD: I'm using Android 1.5 compatible project... maybe phone call is incompatible to 1.5?

2
  • pls paste logcat o/p or elaborate ur error details Jan 27, 2011 at 13:12
  • 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 Aug 14, 2017 at 10:07

10 Answers 10

272

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" />
5
  • 1
    Hi @Lior how could i do in-case that device has dual-sim. Is it possible to make call through a particular sim?
    – Dinash
    Feb 20, 2013 at 11:24
  • 3
    @Dinash: Take a look at this already answered question: stackoverflow.com/questions/13231962/call-from-second-sim
    – Lior
    Mar 1, 2013 at 13:21
  • I have used the same code but not working in the Galaxy S7 edge. This is my code Intent intentCall = new Intent(Intent.ACTION_CALL); String uri = "tel:" + number.trim(); intentCall.setData(Uri.parse(uri)); if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) { startActivity(intentCall); } Dec 8, 2016 at 4:14
  • Can this simulator be used to make calls without physical device Jun 21, 2017 at 7:13
  • Using this intent requires flag FLAG_ACTIVITY_NEW_TASK because it is outside the app.
    – donmj
    Sep 24, 2020 at 10:55
25

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" />
3
  • 1
    number is like 1689,,3,2,1,1 . I am getting issue it will be only 1689..Please help me if you have any solution for the same. Apr 21, 2015 at 11:16
  • @TeraiyaMayur you can remove any non-numeric characters first. So if you have phone number as String number = "1689,,3,2,1,1 do nubmer = "tel:" + number.replaceAll("[^0-9]", "");
    – Walk
    Apr 16, 2017 at 13:20
  • @Walk, a problem is that we want to call with special symbols like ,*. They must be among digits. On an emulator it works right, but on a device it drops additional symbols and digits.
    – CoolMind
    Sep 26, 2019 at 15:15
13
 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.

3
  • Dwivedi Ji : number is like 1689,,3,2,1,1 . I am getting issue it will be only 1689..Please help me if you have any solution for the same. Apr 21, 2015 at 11:17
  • @TeraiyaMayur, It's depends upon IVRS call system. Its work for me because of my calling extinction support take early response. Apr 23, 2015 at 5:32
  • Yes you are right i also get proper valid IVR number and it works fine. thanks Apr 27, 2015 at 10:12
3

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 ?

0
3

This doesn't require a permission.

val intent = Intent(Intent.ACTION_DIAL, Uri.parse("tel:+123456"))
startActivity(intent)

Or

val intent = Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", "+123456", null))
startActivity(intent)

But it shows one more dialog (asking whether you want to call phone just once or always). So it would be better to use ACTION_CALL with a permission (see Revoked permission android.permission.CALL_PHONE).

3

It is working very well. In this way, you do not need to have permission from user. You can open directly phone calling part.

Trick point, use ACTION_DIAL instead of ACTION_CALL.

private void callPhoneNumber() {
    String phone = "***********";
    Intent callIntent = new Intent(Intent.ACTION_DIAL);
    callIntent.setData(Uri.parse("tel:" + phone));
    startActivity(callIntent);
}
2

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();
}
1
  • 1
    @Astor i have defined it very clearly, an i have already gotten points through this, which means that my answer is some what better than the other for some people. Jan 13, 2013 at 19:08
1

If anyone is looking for in Kotlin

    val  uri = "tel:+800******"
    val call_customer_service = Intent(Intent.ACTION_CALL)
    call_customer_service.setData(Uri.parse(uri))
    startActivity(call_customer_service)

Like some other solutions it requires android.permission.CALL_PHONE permission.

0
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 = "123456789";
            String uri = "tel:" + mobileNo.trim();
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse(uri));
            startActivity(intent);
        }
    });*
 }
0

If you end up with a SecurityException (and the call does not work), You should consider requesting the user permission to make a call as this is considered a dangerous permission:

ActivityCompat.requestPermissions(
    activity,
    new String[] {Manifest.permission.CALL_PHONE},
    1
);

Note this has nothing to do with the manifest permission (that you must have as well)

Not the answer you're looking for? Browse other questions tagged or ask your own question.