Hi,
I’m facing this problem with my android plugin since a udpate to the last version of unity.
Java code
public class AndroidBox {
private static final AndroidBox ourInstance = new AndroidBox();
public static Activity mainActivity;
private static final String LOGTAG = "AndroidBox";
public static AndroidBox getInstance()
{
return ourInstance;
}
public interface AlertViewCallback {
public void onButtonTapped(int id);
public void testCallback(String test);
}
public void testCallback(AlertViewCallback callback){
callback.testCallback(("test callback"));
}
public void showAlertView(String[] strings,final AlertViewCallback callback)
{
if (strings.length<3)
{
Log.i(LOGTAG,"Error - expected at least 3 strings, got " + strings.length);
return;
}
DialogInterface.OnClickListener myClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int id) {
Log.i(LOGTAG, "Tapped: " + id);
callback.onButtonTapped(id);
dialogInterface.dismiss();
}
};
AlertDialog alertDialog = new AlertDialog.Builder(mainActivity)
.setTitle(strings[0])
.setMessage(strings[1])
.setCancelable(false)
.create();
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL,strings[2],myClickListener);
if (strings.length>3)
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE,strings[3],myClickListener);
if (strings.length>4)
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE,strings[4],myClickListener);
alertDialog.show();
}
}
c# code
public class AndroidUtilitiesPlugin : MonoBehaviour
{
private AndroidJavaClass _pluginAndroidBoxClass;
private AndroidJavaObject _pluginAndroidBoxInstance;
private void Start()
{
ShowAlertDialog(new string[] { "test","test","ok"});
}
public AndroidJavaClass PluginAndroidBoxClass
{
get
{
if (_pluginAndroidBoxClass == null)
{
_pluginAndroidBoxClass = new AndroidJavaClass(pluginAndroidPath + ".AndroidBox");
_pluginAndroidBoxClass.SetStatic<AndroidJavaObject>("mainActivity", activity);
}
return _pluginAndroidBoxClass;
}
public AndroidJavaObject PluginAndroidBoxInstance
{
get
{
if (_pluginAndroidBoxInstance == null)
{
_pluginAndroidBoxInstance = PluginAndroidBoxClass.CallStatic<AndroidJavaObject("getInstance");
}
return _pluginAndroidBoxInstance;
}
}
public AndroidJavaClass PluginAndroidBoxClass
{
get
{
if (_pluginAndroidBoxClass == null)
{
_pluginAndroidBoxClass = new AndroidJavaClass(pluginAndroidPath + ".AndroidBox");
_pluginAndroidBoxClass.SetStatic<AndroidJavaObject>("mainActivity", activity);
}
return _pluginAndroidBoxClass;
}
}
class AlertViewCallback : AndroidJavaProxy
{
private System.Action<int> alertHandler;
public AlertViewCallback(System.Action<int> alertHandlerIn) : base(pluginAndroidPath + ".AndroidBox$AlertViewCallback")
{
alertHandler = alertHandlerIn;
}
public void onButtonTapped(int index)
{
Debug.Log("Button tapped: " + index);
if (alertHandler != null) alertHandler(index);
}
public void testCallback(string test)
{
Debug.Log(test);
}
}
public void ShowAlertDialog(string[] strings, System.Action<int> handler = null)
{
if (strings.Length < 3)
{
Debug.LogError("AlertView requires at least 3 strings");
return;
}
if (Application.platform == RuntimePlatform.Android)
PluginAndroidBoxInstance.Call("showAlertView", new object[] { strings, new AlertViewCallback(handler) });
else
Debug.LogWarning("AlertView not supported on this platform");
}
}
When calling the ShowAlertDialog the alert dialog is working fine but now when I click on one button a have the error :
Create Thread: Exception : No such proxy method: AndroidUtilitiesPlugin+a.onButtonTapped(System.Int32)
So it’s on the callback of onButtonTapped, but why? Before, I never had that error.