How to make a program call programmatically?

I pass on the activity number to call a bundle

and then, in such an activity, I have a button to call this 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 an Android 1.5 compatible project ... maybe the phone call is incompatible with 1.5?

+114
android phone-call
Jan 27 2018-11-17T00:
source share
8 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); 

Intent in itself is simply an object that describes something. He does not do anything.

Remember to add the appropriate permission to your manifest:

 <uses-permission android:name="android.permission.CALL_PHONE" /> 
+247
Jan 27 '11 at 13:16
source share

Tried this on my phone and it works great.

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

Add this permission to the manifest file.

 <uses-permission android:name="android.permission.CALL_PHONE" /> 
+21
Aug 24 2018-12-12T00:
source share
  Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+198+","+1+","+1)); startActivity(callIntent); 

for multiple ordered calls

This is used for DTMF calling systems. If the call falls, then you must pass more "," between the numbers.

+13
Aug 26 2018-11-11T00:
source share

There is no check for marshmallow resolution in the selected answer. It will not work directly on a device with Marshmallow 6.0 or higher.

I know I'm late, but this question has a big vote, so I thought it would help others in the future.

On marshmallow devices, we need to get runtime permission to call ...

Here is an example to make a marshmallow call or higher.

How to make a call in android marshmallow 6.0 or higher

+6
Aug 14 '17 at 10:07 on
source share

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

Do you have an updated manifest file to grant call rights?

+3
Jan 27 '11 at 13:16
source share

Here I will show you how you can make a phone call from your activities. To call, you need to specify this code in your application.

 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(); } 
+2
Oct. 20 '12 at 23:01
source share
 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
Mar 20 '14 at 6:47
source share

If someone is looking 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) 
0
Apr 15 '19 at 5:38
source share



All Articles