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.

3 1260 3

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

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...
2 1015 0
New
AndroidMan
I’ve tried signing up for Airnow as I used to do very well when they were Airpush, but i haven’t used them in years. I went through the s...
3 872 0
New
ciger
I want to get a clone of Instagram APK But with a difference I want to define in this clone that, for example, it is not possible to acc...
0 553 1
New
DAZ
Is it possible to develop an application that will generate NFC pulses even when the screen is off?
3 347 2
New
tunelabguy
I have an expensive app ($160) in the Play Store that I would like to update. I would like to do a beta test of the update with potentia...
1 233 1
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...
1 228 0
New
faust
Honest question, do companies still use Java for their new android apps? I thought everybody was using Kotlin these days.
4 206 3
New
AnfaengerAlex
Hello, I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
0 1136 2
New
nihar-gingercube
We have developed a audio/video calling functionality using opentok sdk, now we want to integrate speech recognizer for transcribing voic...
1 28 0
New
Dysentery
I am trying to implement the PIN entry page using device’s TEE. I have acquired the confidential OEM Documentation. It have some C++ code...
0 108 1
New

Other popular topics Top

AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
105 4442 50
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
15 7899 19
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
66 20866 24
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
31 3392 15
New
DevotionGeo
The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
21 10897 7
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
155 4170 65
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
21 4534 7
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
52 4629 22
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
31 3576 16
New
CommunityNews
Will Swifties’ war on AI fakes spark a deepfake porn reckoning?
0 5711 0
New

Latest in Questions

View all threads ❯