How to make a call when click on button in Android studio?

319 Views Asked by At

I'm working on a project in which I have created a button.I want to add a feature that if I clicked on that button then it will automatically make a call to police number (100). I have written the code for the same, and when I clicked on that button my mobile phone's dial pad is opening and 100 number is displaying in dial pad. Is there any way to make a call automatically instead of directing me to dial pad?

Can anyone guide me regarding this please?

1

There are 1 best solutions below

0
Pierre On

It is just a matter of how you use the intent, this should dial the number directly:

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

Here is documentation on both ACTION_CALL and ACTION_DIAL.

ACTION_DIAL will only fill in the number in the dialer: Intent.ACTION_DIAL

ACTION_CALL will fill in the number in the dialer and attempt to dial it: Intent.ACTION_CALL