简体   繁体   中英

Xamarin throws Java.Lang.ClassNotFoundException using CallRedirectionService

I created a new Mobile App Xamarin.Forms project using the blank template for this example. I am trying to use CallRedirectionService in my app, but the following exception is thrown.

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();
            }
        }
    }

How can i solve it, since other service doesnt throw any exceptions

eg

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

Android options

Exception

From the screen shots it looks like this code is part of the .NET standard assembly (shared project) which won't reference Mono Android. Instead, try using the Xamarin Forms Dependency Service to invoke the platform-specific things you want from shared code. See my recreation of your code here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM