C # method call with parameter from JS xamarin

I tried to call a C # method from JS with arguments, but I have an error.

I am using Xamarin Android (not Xamarin.Forms)

C # code:

[JavascriptInterface]
[Export("test")]
public Java.Lang.String Test(Java.Lang.String hello)
{
    return hello;
}

      

JS code:

var foo = GameBridge.test('foo');

      

Mistake: System.InvalidOperationException: Specified managed method 'Test' was not found. Signature: (Ljava/lang/String;)Ljava/lang/String;

Error screenshot

+3


source to share


1 answer


The problem is the return type of the C # method. It works well with a return type like "void". Below code works for me.

[JavascriptInterface]
[Export("test")]
public void Test(string hello)
{
    //to do work
}

      



I'm also looking for handling return types in Export / JavascriptInterface.

0


source







All Articles