Alternate for TelecomManager.endCall()

146 Views Asked by At

I have created a test internal application to reject the native phone calls.
I am using below code to reject the calls.

TelecomManager tm = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); tm.endCall();

But the thing is; endCall method is Deprecated.
Is there any alternative for this method?

3

There are 3 best solutions below

0
Lionel Briand On

From the aosp documentation :

* @deprecated Companion apps for wearable devices should use the {@link InCallService} API
* instead.  Apps performing call screening should use the {@link CallScreeningService} API
* instead.

To end the call, your application needs to manage the calls by implementing the InCallService. Your custom service will then have the capabilities to get ongoing calls and disconnect them.

0
Laxmi kant On

Make sure you have add feature-permission in your manifest.xml file

you should use the Telecom framework if your app targets Android 10 (API level 29) and above. The TelecomManager.endCall() method is part of this framework. Java:

  if (android.os.Build.VERSION.SDK_INT >= 
android.os.Build.VERSION_CODES.Q) 
{
TelecomManager telecomManager = getSystemService(TelecomManager.class);
if (telecomManager != null) {
    telecomManager.endCall();
}
}
0
Ivan Abakumov On

You can use InCallService

Example:

  1. Create your own MyInCallService , which is expanded with the help of the InCallService

    import android.telecom.Call;
    import android.telecom.CallScreeningService;
    import android.telecom.InCallService;
    import android.telecom.TelecomManager;
    
    public class MyInCallService extends InCallService {
    
    @Override
    public void onCallAdded(Call call) {
        // Handle incoming call.
        // To disconnect the call, you can use the endCall method.
        call.disconnect();
    }
    }
    
  2. Add your service to the Manifest

     <service android:name=".MyInCallService"
        android:permission="android.permission.BIND_IN_CALL_SERVICE">
         <intent-filter>
             <action android:name="android.telecom.InCallService" />
        </intent-filter>
     </service>
    

You can also use CallScreeningService.