TelecomManager: An exception on AddNewIncomingCall()

273 views Asked by At

I am trying to use Telecom features in my Xamarin.Forms app. When AddNewIncomingCall() is called, an exception is thrown:

Java.Lang.SecurityException: Package com.android.phone does not belong to 10134

Here is the code:

        Xamarin.Forms.Device.BeginInvokeOnMainThread(async () =>
        {            
            TelecomManager telecomManager = (TelecomManager)Application.Context.GetSystemService(TelecomService);

            // https://learn.microsoft.com/en-us/xamarin/essentials/permissions?tabs=android
            PermissionStatus status = await Permissions.CheckStatusAsync<ReadPhoneStatePermission>();
            if (status != PermissionStatus.Granted)
            {
                status = await Permissions.RequestAsync<ReadPhoneStatePermission>();
            }

            PhoneAccountHandle phoneAccountHandle = telecomManager.CallCapablePhoneAccounts.FirstOrDefault();
            
            telecomManager.AddNewIncomingCall(phoneAccountHandle, new Bundle());
        });

How can I fix this issue?

0

There are 0 answers