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

Prosper226
Hi guys, I’m trying to do multi ussd with java on android, I can’t do it. I looked at the documentation of telephonyManager on android, ...
New
CristianM92
Hi, I’m working on an app who make the conversion between decimal degrees and degrees minutes seconds. I have to make an “Export” button ...
New
Aathithyan
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.
New
mpdizcashtag
Hi, this is my parrition informarion. A week ago I erased ‘system’ and now my hotpepper puya tablet bootloops. I have a gsi im trying to...
New
faust
Honest question, do companies still use Java for their new android apps? I thought everybody was using Kotlin these days.
New
Briannamari
Old android photo name sequence Help decoding file names Example. I want to see if a file name aligns with a time / date in which the p...
New
hasan10242048
There is an Android app. I just want to create two GRAPHS with CPU Runtime and Battery Consumption. It is as simple as this. I tried w...
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...
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
Alan
I need to create an android app to receive contactless payment from my clients. how can I start that? My clients will be phisicaly in the...
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
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...
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
New
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New
First poster: joeb
The File System Access API with Origin Private File System. WebKit supports new API that makes it possible for web apps to create, open,...
New
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
New
sir.laksmana_wenk
I’m able to do the “artistic” part of game-development; character designing/modeling, music, environment modeling, etc. However, I don’t...
New
OSZAR »