【发布时间】:2017-01-24 12:20:26
【问题描述】:
我的 MainActivity 中有:
webView.addJavascriptInterface( new JavaScriptInterface( this ), "ajaxHandler" );
....
public class JavaScriptInterface
{
Context mContext;
JavaScriptInterface( Context c ) {
mContext = c;
}
public void DoSomething( String dataToPrint )
{
.....
}
}
我读到问题可能是proguard。 所以我更新了proguard规则文件:
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
-keep public class com.example.testapp.JavaScriptInterface
-keep public class * implements com.example.testapp.JavaScriptInterface
-keepclassmembers class * implements com.example.testapp.MainActivity.JavaScriptInterface{
public *;
}
虽然没有帮助...在 chrome 调试器中,由于我在控制台中放入了 ajaxHandler 对象和 DoSomething 方法,所以我可以看到 ajaxHandler 对象为Object {}
但它是空的,方法DoSomething是undefined
【问题讨论】:
标签: javascript java android ajax webview