how to use AndroidJavaProxy for Java generics callback
I have a Java android lib from other company
package com.games.sdk.api.callback;
public abstract interface APICallback<T>
{
public abstract void onCompleted(T paramT);
}
I need to overwrite it in unity, so I try something like this but isn't work
class APICallback <T> : AndroidJavaProxy
{
public APICallback()
: base("com.games.sdk.api.callback")
{
}
public void onCompleted(T paramT)
{
Debug.Log("done");
}
}
here is my calling
AndroidJavaClass ResponseLoginData = new AndroidJavaClass("com.games.sdk.entity.response");
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject SDKAPI_instance = new AndroidJavaClass("com.games.sdk.login");
SDKAPI_instance.Call ("login",jo,new R2APICallback<ResponseLoginData>());
how to get class type from lib? I just new to mix java android code with unity c# code. Thank in advance
Answer by NNSkelly · Jan 07 at 08:18 PM
YMMV, and I'm now running into other issues which may be arising from this approach, but in my current project what's at least not yielding any syntax or java errors is playing fast and loose and embracing the fact that at the end of the day, everything is an AndroidJavaObject that will need to be worked using .Get/Call invocations anyway. Just leave off the typing entirely since there's no C#-level syntax to point at the desired Java-level class (anything you specify in <> at the C# level is implicitly a C# type). E.g.
public class IMyInterfaceProxy : AndroidJavaProxy
{
// public interface IMyInterface<T>
public IMyInterface() : base("com.org.net.iMyInterface") { }
// void foo(T t)
public void foo(AndroidJavaObject t)
{
// ...
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612151240im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
LitJson: unknown JSON and TypeInstantiation Exceptions, invalid tokens 0 Answers
ToshibaTeli USB3.0 Camera dotNet Library not working in Unity 0 Answers
OpenCVForUnity 0 Answers
How demanding is StateMachineBehaviour? 1 Answer
I add android:configChanges: layoutDirection to AndroidManifest, but after build, it is not exist! 0 Answers