136

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?

Abhishek Jain
  • 3,562
  • 2
  • 26
  • 44
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
  • pls paste logcat o/p or elaborate ur error details – chikka.anddev Jan 27 '11 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](http://androiderstack.com/index.php/2017/08/02/how-to-make-call-in-android-marshmallow-6-0-or-above/) – Vishal Chhodwani Aug 14 '17 at 10:07

10 Answers10

271

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" />
The Alpha
  • 143,660
  • 29
  • 287
  • 307
Lior
  • 7,845
  • 2
  • 34
  • 34
  • 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 '13 at 11:24
  • 3
    @Dinash: Take a look at this already answered question: http://stackoverflow.com/questions/13231962/call-from-second-sim – Lior Mar 01 '13 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); } – AngelJanniee Dec 08 '16 at 04:14
  • Can this simulator be used to make calls without physical device – user3754136 Jun 21 '17 at 07:13
  • Using this intent requires flag FLAG_ACTIVITY_NEW_TASK because it is outside the app. – donmj Sep 24 '20 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" />
Anirudh
  • 2,767
  • 5
  • 69
  • 119
  • 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. – Teraiya Mayur Apr 21 '15 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 '17 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 '19 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.

Ashish Dwivedi
  • 8,048
  • 5
  • 58
  • 78
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 ?

ykatchou
  • 3,667
  • 1
  • 22
  • 27
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).

CoolMind
  • 26,736
  • 15
  • 188
  • 224
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);
}
canerkaseler
  • 6,204
  • 45
  • 38
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();
}
B770
  • 1,272
  • 3
  • 17
  • 34
Pir Fahim Shah
  • 10,505
  • 1
  • 82
  • 81
  • 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. – Pir Fahim Shah Jan 13 '13 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.

CoolMind
  • 26,736
  • 15
  • 188
  • 224
Mughil
  • 705
  • 7
  • 8
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);
        }
    });*
 }
Napoleon
  • 340
  • 3
  • 13
Muhammad Usman Ghani
  • 1,279
  • 13
  • 19
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)

Li3ro
  • 1,837
  • 2
  • 27
  • 35