NullPointerException NullPointerException - 1 year ago 92
Android Question

How to make a phone call programatically?

im passing to a 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?

Answer Source

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")));

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" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download