DKG
DKG

Reputation: 1127

How to add button to call a specific number

I want to add a button to my app that will allow the phone to call a particular number. I also want to add message service.

Upvotes: 1

Views: 304

Answers (4)

Andrei
Andrei

Reputation: 2607

Set the permissions in the manifest file:

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> 

Add this in the onClick:

Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:123456789"));
    startActivity(callIntent);

Upvotes: 3

jeet
jeet

Reputation: 29199

write following code in button.onClickListener,

String url = "tel:3334444";
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));

Upvotes: 1

Hend
Hend

Reputation: 599

Refer to this example on making a Phone Call.

Upvotes: -1

prakash
prakash

Reputation: 654

try this code for calling particular number

call.setOnClickListener(new View.OnClickListener() {//here call is the button
        public void onClick(View v) {
            try {
                String Numb = "tel:" + repphone;// repphone is phonr num
                Intent intent = new Intent(Intent.ACTION_CALL, Uri
                        .parse(Numb));
                startActivity(intent);
            } catch (Exception e) {
                // Modules.showLongMessage(contact.this, e.getMessage());
            }
        }
    });

Upvotes: 2

Related Questions