【发布时间】:2016-11-29 06:32:00
【问题描述】:
我想在一个android应用程序中调用一个带有Java参数的javascript函数,我不需要在webview中加载它,因为我只需要调用它并从资产中的JS文件中获取结果文件夹。
我是在 iOS 上使用 JavascriptCore 完成的,但在 android 中找不到相同的功能。
查找了 AndroidJSCore 和 Rihno,但文档和教程对此主题不清楚。
我将 JS 文件加载到 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();
}
要发送的参数来自Edittexts。
javascript函数接受2个参数并返回JSON
function authenticate(uName, pWord)
{
var authenString = JSON.stringify(authenJSON);
return authenString;
}
感谢任何帮助。
【问题讨论】:
标签: javascript java android