Xamarin 使用 CallRedirectionService 抛出 Java.Lang.ClassNotFoundException

Xamarin throws Java.Lang.ClassNotFoundException using CallRedirectionService

我使用此示例的空白模板创建了一个新的移动应用程序 Xamarin.Forms 项目。我试图在我的应用程序中使用 CallRedirectionService,但抛出了以下异常。

Java.Lang.ClassNotFoundException: crc64bf934172c93e128d.MyCallService ---> Java.Lang.NoClassDefFoundError: Failed resolution of: Landroid/telecom/CallRedirectionService; ---> Java.Lang.ClassNotFoundException: Didn't find class "android.telecom.CallRedirectionService" on path: DexPathList[[zip file "/data/app/com.companyname.xam-8bL_MB0IWItrj3Z69Zwvtw==/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.xam-8bL_MB0IWItrj3Z69Zwvtw==/lib/x86, /data/app/com.companyname.xam-8bL_MB0IWItrj3Z69Zwvtw==/base.apk!/lib/x86, /system/lib]]

using Android.Telecom;
using Xamarin.Forms;    
namespace xam
    {
        public class MyCallService : CallRedirectionService
        {
            public override void OnPlaceCall(Android.Net.Uri handle, PhoneAccountHandle initialPhoneAccount, bool allowInteractiveResponse)
            {
                //throw new NotImplementedException();
            }
        }
        public partial class MainPage : ContentPage
        {
            public MainPage()
            {
                var callCervice = new MyCallService();
                InitializeComponent();
            }
        }
    }

我该如何解决它,因为其他服务不会抛出任何异常

例如

public class CallPreventer : InCallService
{
    public override void OnCallAdded(Call call)
    {
        call.Disconnect();
        base.OnCallAdded(call);
    }
}

Android options

Exception

从屏幕截图来看,这段代码似乎是 .NET 标准程序集(共享项目)的一部分,不会引用 Mono Android。相反,请尝试使用 Xamarin Forms Dependency Service to invoke the platform-specific things you want from shared code. See my recreation of your code here.