I would like to call a javascript function with parameters from Java in an android app, I don't need to load it in webview as I just need to call it and get the results from the JS file which is in the assets folder.
I did it on iOS using JavascriptCore, but I can't find the same functionality in android.
Looked up AndroidJSCore and Rihno but the docs and tutorials are not clear on the subject.
I load the JS file into a String , further I can't go as how to send the parameters and get the results.
Here is how load the file into a string :
AssetManager assetManager = getAssets();
String jsFile;
// To load js file
InputStream input;
try {
input = assetManager.open("authenticate.js");
int size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
input.close();
// byte buffer into a string
jsFile = new String(buffer);
resultTV.setText(jsFile);
Log.d("TAG", jsFile);
} catch (IOException e) {
e.printStackTrace();
}
The parameters to send come from Edittexts.
The javascript function take 2 parameters and return JSON
function authenticate(uName, pWord)
{
var authenString = JSON.stringify(authenJSON);
return authenString;
}
Any help is appreciated.