I tried to pass a string parameter to the web app javascript code. It's failed while passing a variable with the string value. But it works when we hardcode the data. Please let me know what's wrong with this.
Working hardcoded code:
mWebview.evaluateJavascript("cm.setData('N051783')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value3) {
Log.d(" setData Return Value"," setData Return... "+value3);
}
});
Not working code with string variable
mWebview.evaluateJavascript("cm.setData("+sub_data+")", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value3) {
Log.d(" sub_data Return Value"," sub_data Return... "+value3);
}
});
You are probably missing ""
My JavaScript function at com.UserProfile
How to call it from Java
How to pass the parameter?
You need to concatenate " with parameter. " is a special character. This is how you can concatenate " in a String.
Here is an example:
You can use StringBuilder to concatenate as well as"
Let's break it down line by line;