7

I have small app created with Xamarin for android, where I have WebView for displaying some data and than backing up it with C# code for storing data. To get data from webview I use javascript and in C# I have method like this:

[Export("addMood2")]
[JavascriptInterface]
public String saveData(string data) { ...}

and than I call it from JS code (I have webView.AddJavascriptInterface and all necessary stuff). So it works if I pass string, but of course in javascript I create some object and what to save it (it more or less always same structure), so for now I stringify it and than passing as string, parsing on C# side and have data. But is it possible to pass that object from JS directly - as Dictionary or some mapped structure? If I try to use "saveData(Java.Lang.Object data)" data is always null, so I guess it doesn't like type mapping.

Dainius
  • 1,765
  • 1
  • 17
  • 36
  • You should look through the documentation on this item. There are quite a few notes that should help: https://developer.xamarin.com/api/member/Android.Webkit.WebView.AddJavascriptInterface/p/Java.Lang.Object/System.String/ i.e. Note that injected objects will not appear in JavaScript until the page is next (re)loaded. For example: – Jon Douglas Jun 30 '16 at 23:17
  • I did look at documentation, sadly all examples I could find was like: "@JavascriptInterface public String toString() { return "injectedObject"; }" and if there was any parameter, it always string type. That's why I tried to find here. – Dainius Jul 01 '16 at 17:10

0 Answers0