AndroidJavaProxy no such method exception,AndroidJavaProxy no such proxy method error

I’m trying to create a plugin that allows me to access an SDK from my game. I can call SDK methods just fine using AndroidJavaObject and I can pass data to them with no issue. But there are some SDK methods that require an interface to be passed.

After searching to how to use interfaces in unity i found AndroidJavaProxy, and i follow this tutorial and this is my code:

class DailyBudgetCallback : AndroidJavaProxy
	{
		public DailyBudgetCallback() : base("ir.ordibehesht.sdk.sdk.playservices.interfaces.DailyBudgetCallback") { }
		public void onDailyBudgetResponse(DailyBudget dailyBudget) {				
			Debug.Log("daily budget response ");
		}
	}

After running application and calling my method i get this error :
Unity: Exception: No such proxy method : DailyBudgetCallback.onDailyBudgetResponse(UnityEngine.AndroidJavaObject)

what’s my problem ? can any body help me please ?

The first thing to do is read the documentation for AndroidJavaProxy to give you a basic concept of what this class does and what it should be used for.

Typically, you would use this class when you need to callback from Java code back to your Unity C# code. It helps by removing some of the “messy” code you have to write to achieve that.

In order to use AndroidJavaProxy, you must have a Java interface that you wish to implement. You then declare a new class derived from AndroidJavaProxy that should define the methods that will be called back from Java.

Optionally, you can define a C# interface that matches the Java interface so you don’t forget to implement any of the required methods (this is not a must, in case there’s no interface defined, Unity will try to match the methods by name).

Now to your code in question:

class DailyBudgetCallback : AndroidJavaProxy
{
	public DailyBudgetCallback()
		: base("ir.ordibehesht.sdk.sdk.playservices.interfaces.DailyBudgetCallback")
	{
	}

	public void onDailyBudgetResponse(DailyBudget dailyBudget)
	{                
		Debug.Log("daily budget response ");
	}
}

You defined a new class that is derived from AndroidJavaProxy, passing the name of the required Java interface in its constructor. So far so good.

The callback method onDailyBudgetResponse receives a parameter called DailyBudget. You didn’t specify what this object is.

If this is an object that is defined in Java, your C# code knows nothing about it (even if you created a matching type in your C# code).

If that is the case, you should declare it as a AndroidJavaObject type. What this means is that effectively your callback is called, passing a reference to a Java type that you can interact with, using the AndroidJavaObject object instance.

Hello @liortal,

In your response to @FarshidAbz you said:

The callback method onDailyBudgetResponse receives a parameter called DailyBudget. You didn’t specify what this object is.

If this is an object that is defined in Java, your C# code knows nothing about it (even if you created a matching type in your C# code).

If that is the case, you should declare it as a AndroidJavaObject type. What this means is that effectively your callback is called, passing a reference to a Java type that you can interact with, using the AndroidJavaObject object instance.

Can you please elaborate more on this as to where do we need to declare AndroidJavaObject in our unity c# callback parameter or at the java end?

Also can you show us an small code snippet explaining what you meant.

That would be a really great help for all.

Regards,

Iceheros.