I have code in Unity that calls a function programmed in Java for Android using AndroidJavaClass and AndroidJavaObject and I would like to pass this code to a dll in C# .Net but I can't find an easy way to call Java functions using C# .Net since the AndroidJavaObject and AndroidJavaClass classes are exclusive to the Unity dll, here is an example of my code:
Java (Android):
public class DeviceManager {
public interface DeviceListener {
void DoSomething();
}
private DeviceListener deviceListener;
public DeviceManager(DeviceListener deviceListener){
this.deviceListener = deviceListener;
}
public String[] getSomeData(){
return new String[]{};
}
}
C# (Unity):
public class DeviceListener : AndroidJavaProxy
{
DeviceManager deviceManager;
public DeviceListener(DeviceManager manager) : base("com.myapp.DeviceManager$DeviceListener")
{
this.deviceManager = manager;
}
public void DoSomething();
}
public class DeviceManager
{
private AndroidJavaObject jo;
public DeviceManager(){
jo = new AndroidJavaObject("com.myapp.DeviceManager", new DeviceListener(this));
}
public string[] GetData(){
AndroidJavaObject returnedData = jo.Call<AndroidJavaObject>("getSomeData");
return AndroidJNIHelper.ConvertFromJNIArray<string[]>(returnedData.GetRawObject());
}
}
What is the best way to do that example in C# .Net instead of Unity?
EDIT: my main question is related to know how to get objects and call functions from an .aar file in .NET Framework inside a dll C# file for Unity
EDIT 2: I found some information about Xamarin, maybe that is what I am looking for?: https://github.com/xamarin/monodroid-samples/tree/master/JavaIntegration/AarBinding But even though I could link an .aar file to a dll in C# that doesn't quite answer my question in the best way to create a code that works the same as the example described above
EDIT 3: Currently, to solve this problem, I am using the UnityEngine .dll in my Visual Studio project but I want to generate a .dll for use in other graphics engines so I would like to be able to find a different solution than using Unity's own .dll for solve this problem, hence I mentioned Xamarin since it is a good way to communicate .Net Framework with Android (Java) but I have not found any example that uses it outside of a mobile application created in Visual Studio since in my case I would need to obtain objects and call functions from the .aar file