[英]Sending value from java to javascript using JavaScriptInterface
Android App has: Android App具有:
JavaScriptNFCInterface NFCIDConnector = new JavaScriptNFCInterface(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(NFCIDConnector, "Android");
public class JavaScriptNFCInterface {
public JavaScriptNFCInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public String getNFCID() {
return NFCID;
}
}
And for testing purpose in UI: 为了在UI中进行测试:
<a class="btn btn-primary" href="#" onclick="console.log(Android.getNFCID)" role="button">test</a>
but im receiving only: 但我只收到:
chromium﹕ [INFO:CONSOLE(1)] "function () { [native code] }", source: http://192.168.173.216:8082/#/tablet/index (1)
not string with ID. 不是ID的字符串。
You are missing parentheses after the function name, so instead of calling it, you are just printing it. 函数名称后缺少括号,因此您无需打印它,而只是打印它。 You need to replace:
您需要更换:
console.log(Android.getNFCID)
with: 与:
console.log(Android.getNFCID())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.