3

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!

R-Dub
  • 511
  • 2
  • 5
  • 8

7 Answers7

17
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>
Naskov
  • 4,121
  • 5
  • 38
  • 62
  • 3
    Wow! 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. – R-Dub May 07 '13 at 06:36
  • @Nucleotide I'm glad I could help. Anytime :) – Naskov May 07 '13 at 06:38
2

i think you Must add <uses-permission android:name="android.permission.CALL_PHONE" /> in Manifest.

null pointer
  • 5,874
  • 4
  • 36
  • 66
2

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

Hoan Nguyen
  • 18,033
  • 3
  • 50
  • 54
2

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):

Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
1

Try this.

startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneno)));

Also, add the permission android.permission.CALL_PHONE in your manifest file.

Rahul
  • 44,383
  • 11
  • 84
  • 103
1

Add the following in the manifest file and it should work fine -

    <uses-permission android:name="android.permission.CALL_PHONE"/>
user1721904
  • 843
  • 4
  • 13
-2

In your Android Phone Go to: "Setting"-> "InstalledApp"-> "find your app"-> "App Permission"-> "Here allow the "Telephone Permission" Hope it will help you