How can I call a number from button press in Android?
Solution 1
String number = "12345678";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" +number));
startActivity(intent);
You need to add this Permission to your manifest.
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
Solution 2
i think you Must add <uses-permission android:name="android.permission.CALL_PHONE" />
in Manifest.
Solution 3
If you want the dialer to open with the number use ACTION_DIAL
Intent i=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:" + phoneno));
You do not need any permission
Solution 4
Make sure you have added the
<uses-permission android:name="android.permission.CALL_PHONE" />
tag at a correct level in the AndroidManifest.xml file (outside the
<application ... />
tag but within the <manifest ... />
tag):
Solution 5
Try this.
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneno)));
Also, add the permission android.permission.CALL_PHONE
in your manifest
file.
Nucleotide
Qualified Personal Trainer, health and fitness fanatic, motorcyclist, love my gadgets and other tech toys.
Updated on June 07, 2022Comments
-
Nucleotide almost 2 years
I'm very much a beginner at this and I'm struggling to get this to work.
When button is pressed, I simply want the dialer to open with the specified number automatically inputted.
So far I've tried the following:
Button btn_call_us = (Button) findViewById(R.id.btn_call_us); btn_call_us.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:00000000")); startActivity(callIntent); } });
I've also tried:
Button btn_call_us = (Button) findViewById(R.id.btn_call_us); btn_call_us.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String phoneno="00000000"; Intent i=new Intent(Intent.ACTION_CALL,Uri.parse(phoneno)); startActivity(i); } });
I've added the permission ACTION_CALL to the manifest.
Whenever I click the Call button the app force closes.
Any assistance would be greatly appreciated.
Thank you!
-
Nucleotide about 11 yearsWow! First time using SO and really wasn't expecting such a quick response. Thank you very much. This worked perfectly. I made one change and that was ACTION_CALL to ACTION_DIAL so it gives the user the option to back out or confirm the call.
-
Naskov about 11 years@Nucleotide I'm glad I could help. Anytime :)