我有办法在cordova中显示来自android java文件的消息吗?我尝试过alert,log.i,console.log,print和System.out.println,但没有任何效果。通过构建应用程序,会出现错误。
例如:
log.w("test");
error: no suitable method found for w(String)
只有callbackContext有效,但发送成功或失败的返回,此时代码就会停止。
编辑:
System.out还没有出现任何内容,现在我尝试了几个小时来处理loadUrl但收到如下错误消息:
error: variable mainView might not have been initialized
代码:
import org.apache.cordova.CordovaWebView;
public class VideoCapture extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
CordovaWebView mainView;
mainView.loadUrl("javascript:alert('hello');");
如何实施webView?
答案 0 :(得分:0)
如果您使用System.out
,它应该出现在logcat
如果你想从java执行javascript代码,可以使用loadUrl
方法,这样你就可以使用javascript alert
或console.log。示例:
webView.loadUrl("javascript:alert('hello');");
或在UI线程
上运行它cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
webView.loadUrl("javascript:alert('hello');");
}
});
或者这个在主线程上运行
cordova.getThreadPool().execute(new Runnable() {
public void run() {
webView.loadUrl("javascript:alert('hello');");
}
});