Is there any documentation regarding the WebView JavaScript Bridge? I am looking for documentation that describes the capabilities and supported data types for methods defined within the "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 within JavaScript and run it in the emulator, everything seems to work fine. If I run this on my NexusOne, the passed in "num" argument is always "0".
If I change the above to:
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 am wondering if JavaScriptInterface method arguments should/can 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
You can either require String args on the Java side or ensure that numbers are actual numbers (and not text versions of numbers - see about.com - JavaScript: Strings to Numbers) on the JavaScript side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With