Connect when clicking a button

2

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

As I did, it calls the Action_Diall activity with the number already written, so the person must click again to make the call.

Is it possible that clicking this button (of the app) already makes 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);
        }
    
asked by anonymous 21.01.2017 / 18:00

1 answer

2

To make phone calls on Android directly, you should use ACTION_CALL . Here's how it would look:

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

In addition, you need to give permission on your manifest android.permission.CALL_PHONE .

See more details in the documentation .

    
21.01.2017 / 18:52