Aathithyan

Aathithyan

I don't know how to implement outgoing call feature in android studio using Kotlin

I need to know how to implement outgoing call in my custom application instead of using default phone call app i need my own app call.

Most Liked

comfygenpvt

comfygenpvt

Implementing outgoing calls in a custom Android application involves several steps. Below is a basic outline to guide you through the process. Note that this is a simplified overview, and you may need to adjust the code based on your specific requirements.

Add Permissions: Ensure that you have the necessary permissions in your AndroidManifest.xml file:

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

Create UI for Dialing: Design a user interface (UI) for dialing a phone number. You can use EditText for the phone number input and a Button to trigger the call.

<EditText
    android:id="@+id/editTextPhoneNumber"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="phone" />

<Button
    android:id="@+id/buttonCall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Call" />

Handle Call Button Click: In your activity or fragment, handle the button click event and initiate the call:

Button buttonCall = findViewById(R.id.buttonCall);
buttonCall.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        String phoneNumber = ((EditText) findViewById(R.id.editTextPhoneNumber)).getText().toString();
        makePhoneCall(phoneNumber);
    }
});

Implement makePhoneCall Method: Create a method to initiate the phone call using an Intent . This will launch the default phone app with the specified phone number:

private void makePhoneCall(String phoneNumber) {
    Intent dialIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
    startActivity(dialIntent);
}

Note: Starting from Android 23 (Marshmallow), you need to request the CALL_PHONE permission at runtime. You can check for permission before making the call and request it if necessary.

if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
    makePhoneCall(phoneNumber);
} else {
    // Request permission
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, CALL_PHONE_PERMISSION_REQUEST_CODE);
}

Handle the permission result in the onRequestPermissionsResult method.

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    if (requestCode == CALL_PHONE_PERMISSION_REQUEST_CODE) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            makePhoneCall(phoneNumber);
        } else {
            Toast.makeText(this, "Call permission denied", Toast.LENGTH_SHORT).show();
        }
    }
}

Remember to replace CALL_PHONE_PERMISSION_REQUEST_CODE with a constant value defined in your code.

Please note that the CALL_PHONE permission allows your app to make calls directly without user interaction. Ensure that you comply with privacy and security guidelines when implementing such features in your application.

Veeran

Veeran

To implement outgoing calls in your custom application, you can use Android’s TelephonyManager and Intent classes. First of all, request the necessary permissions in your AndroidManifest.xml. Then, use TelephonyManager to check if the device is capable of making calls. If yes, use Intent.ACTION_CALL to initiate an outgoing call with the desired phone number. Also, ensure you handle the appropriate permissions and runtime checks to avoid issues.
Regards

Where Next?

Popular Android topics Top

big_f
I am making an app with Nativescript-vue and I would like to have an event where I click on an icon and then a new box appears. For the i...
New
tauseeqafzal
Question: Android Developer → is there any way to read the .trash directory? → we can copy or save the file before delete ? #android...
New
Joakins
Android studio displayed access is denied during gradle build C:\Program Files\Java\jdk1.8.0_251\native\68d5fa5c4cc2d200863cafc0d521ce42...
New
mfaamir
Dear Sir, I am a beginner in Android App development and I am currently trying to establish a connection between my Android Studio Java ...
New
cve60069
Hello I am starting the tearning curve to writing an app for my galaxy phone. Me and my friens play a lot of “Texas Hold-Em” and, for t...
New
vsiPr
I am trying to develop an app which will make your smartphone act as a “keyboard”. I need it to send different symbols to another devices...
New
Rodion
Hello everyone, I recently started learning Kotlin and downloaded Android Studio, but after writing my first code and trying to run it, I...
New
codergrid
I’m new to Android Studio, and curious about how long you’ve been using your Android Studio IDE. I read on Wikipedia that this year, Andr...
New
Garrett
I’m stuck trying to understand how to get a variable initialised, and later updated, in kotlin to update in Jetpack Compose and cause a c...
New
Devraj5032
I’m using TensorFlow Lite (TFLite) with React Native Expo. When I test the app using the Expo Go app, everything works fine. However, whe...
New

Other popular topics Top

AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File &gt; New Rule: And select Deny, O...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New
AstonJ
Curious what kind of results others are getting, I think actually prefer the 7B model to the 32B model, not only is it faster but the qua...
New