Home > Enterprise >  Convert Call.Callback class from Android Java to Xamarin Android
Convert Call.Callback class from Android Java to Xamarin Android

Time:06-08

I already convert overall of the source code but for Call.Callback is unable to convert is there anywhere to use it on C#, Sorry that I am new on Xamarin (C#). In Additional, I would like to using "callback" in RegisterCallBack(), it work on java but not in c#.

private Call.Callback callback = new Call.Callback() {
    public void onStateChanged(Call call, int state) {
        
    }
}; 
public void onCallAdded(Call call)
    {
        call.RegisterCallback(callback);
        PhoneCallManager.call = call;
    }

CodePudding user response:

The code you provided is the anonymous inner class in Java. For C#, if you want to add or override a method in a class, you need to create a class to extend it and then add or override the method you want. Such as:

public class MyCallback : Call.Callback
{
    public void onStateChanged(Call call, int state)
    {
        CallManager.updateCall(call);
    }
}

In addition, how do you get the CallManager? I had checked the resource code of the Call.Callback, there is no instance of CallManager in it. According to this link, it seems that you need to use the classloader to get the CallManager.

Update

private MyCallback callback = new MyCallback();

public void onCallAdded(Call call)
{
    call.RegisterCallback(callback);
    PhoneCallManager.call = call;
}
  • Related