NullPointerException NullPointerException - 4 months ago 9
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

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" />
Comments