Wednesday, February 7, 2018

How to make Phone Calls In Android

In Android we can make Phone calls to a particular Phone Number using Intents.

Permission Required


You need to write <uses-permission android:name="android.permission.CALL_PHONE" />  in order to make a call 

You will use ACTION_CALL action to trigger built-in phone call functionality available in Android device. Following is simple syntax to create an intent with ACTION_CALL action

Intent phoneIntent = new Intent(Intent.ACTION_CALL);

You can use ACTION_DIAL action instead of ACTION_CALL, in that case you will have option to modify hardcoded phone number before making a call instead of making a direct call.

To make a phone call at a given number 91-000-000-0000, you need to specify tel: as URI using setData() method as follows −

Intent callIntent = new Intent(Intent.ACTION_CALL);
            if (ActivityCompat.checkSelfPermission(MainActivity.this,
               Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

No comments:

Post a Comment