3

I tried to call C# method from JS with arguments, but I've got an error.

I'm 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');

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

Error screenshot

suhotrub
  • 118
  • 1
  • 7
  • I made a basic demo but didn't reproduced your problem, Could you please try follow the [Call C# from JavaScript](https://developer.xamarin.com/recipes/android/controls/webview/call_csharp_from_javascript/). If the error persists, could you please share a basic demo that can reproduce this problem? – Elvis Xia - MSFT Mar 23 '17 at 03:17

1 Answers1

0

The problem is the return type of the c# method. It works well with return type as 'void'. Below code working to me.

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

I am also looking for to handle return types in Export/JavascriptInterface.

sun wells
  • 1
  • 2