Robert
Robert

Reputation: 11

How to end GSM call programmatically on Android 10

We develop an Android app which is capable of ending a GSM call. We used this solution for years: end incoming call programmatically

On Android 10 this solution unfortunately fails. I can't find any other solution which actually works on Android 10. Any suggestions?

Upvotes: 0

Views: 1445

Answers (1)

Robert
Robert

Reputation: 11

It is possible to stop GSM call on Android 10. Next code is in Xamarin Android API level 27 using reflection.

First request for permission:

// Check permission AnswerPhoneCalls
if (ContextCompat.CheckSelfPermission(context, Android.Manifest.Permission.AnswerPhoneCalls) != (int)Permission.Granted)
        {
            activity?.RunOnUiThread(() =>
                ActivityCompat.RequestPermissions(activity, new string[1] { Android.Manifest.Permission.AnswerPhoneCalls }, 0));
        }

Then stop GSM call by:

TelecomManager telecomManager = (TelecomManager)activity.GetSystemService(Context.TelecomService);
            var endcall = telecomManager.Class.GetDeclaredMethod("endCall");
            endcall.Accessible = true;
            endcall.Invoke(telecomManager);

Upvotes: 1

Related Questions