JavaScript WebView Bridge Documentation

Is there any documentation regarding WebView JavaScript Bridge? I am looking for documentation that describes the capabilities and supported data types for methods defined in "JavascriptInterface".

For example, if I define the following:

public class JavaScriptInterface { public int incrementNumber(int num) { return num + 1; } 

If I call this method from JavaScript and run it in the emulator, everything will work fine. If I ran this on my NexusOne, the passed in argument "num" is always "0".

If I changed above:

  public class JavaScriptInterface { public int incrementNumber(String num) { // Leaving out try/catch int tempNum = newRadius = Integer.parseInt(num); return tempNum + 1; } 

... everything seems to work. So I'm wondering if the arguments to the JavaScriptInterface / method should only be of type String?

Relevant resources: http://developer.android.com/reference/android/webkit/WebView.html http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object, java.lang.String) http://code.google.com/apis/maps/articles/android_v3.html

+4
source share
2 answers

You can either require String arguments on the Java side, or make sure the numbers are real numbers (not textual versions of numbers - see about.com - JavaScript: Strings to Numbers ) from the JavaScript side.

+1
source

The only relevant white paper is here: http://developer.android.com/guide/webapps/webview.html But a description of the types available

+1
source

Source: https://habr.com/ru/post/1338783/


All Articles