Connect by clicking a button

Asked

Viewed 53 times

2

I would like to know how to make that when clicking on a button, a Telephonic call to the number.

As I did, he calls Activity Action_diall with the number already written, so the person must click again to make the call.

It is possible that by clicking this button (from the app) already carry out the call?

Follow the code below:

else if (id == R.id.btn_call){
            String celular = saveSharedPreferences.getNumber(getContext());
            intent = new Intent(Intent.ACTION_DIAL);
            intent.setData(Uri.parse("tel:"+celular));
            startActivity(intent);
        }

1 answer

2


To make phone call on Android directly, you must use ACTION_CALL. See how it would look:

Intent call = new Intent(Intent.ACTION_CALL);
call.setData(Uri.parse("tel:"+celular));
startActivity(call);

Also, it is necessary to give permission in your manifest android.permission.CALL_PHONE.

See more details in the documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.