小编Uma*_*war的帖子

了解Android webview javascript界面

我创建了一个android WebView,并javascript使用注入接口addJavascriptInterface(mObject, "jsinterface").它工作正常,直到我使用new运算符在JavaScript中创建具有相同名称(jsinterface)的对象.

我的Java代码:

WebView mWebView = findViewById(R.id.myWebView);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebChromeClient(new MyWebChromeClient((Activity)mContext));
mWebView.addJavascriptInterface(new testClass(), "jsinterface");
mWebView.loadUrl("UrlToLoad");
Run Code Online (Sandbox Code Playgroud)

testClass.java

public class testClass{
    public testClass() {
    }

    @JavascriptInterface
    public String testNativeMethod() {
        return "Java method called!!";
    }
}
Run Code Online (Sandbox Code Playgroud)

我的Java脚本代码

test.js

function test(msg){
    this.message = msg;

    this.testJSMethod = function(){
        return this.message;
    }
}

alert(jsinterface.testNativeMethod()); // prints Java method called!!
jsinterface= new test("JS method called...");
alert(jsinterface.testJSMethod()); // prints JS method called...
alert(jsinterface.testNativeMethod()); // errors "NPMethod called on non- NPObject" …
Run Code Online (Sandbox Code Playgroud)

javascript java android webview

7
推荐指数
2
解决办法
1万
查看次数

将 PyCharm 项目中的所有文件的 CRLF 更改为 LF

我想将在 PyCharm 中打开的项目中的所有文件的 CRLF 更改为 LF。我已更新项目设置以使用“文件 -> 设置 -> 编辑器 -> 代码样式”中的 LF 行分隔符,如果不打开这些文件,它不会更改现有文件。

有没有办法将 PyCharm 中所有现有文件的 CRLF 更改为 LF?

pycharm

7
推荐指数
1
解决办法
3770
查看次数

标签 统计

android ×1

java ×1

javascript ×1

pycharm ×1

webview ×1