I have in my MainActivity:
webView.addJavascriptInterface( new JavaScriptInterface( this ), "ajaxHandler" );
....
public class JavaScriptInterface
{
Context mContext;
JavaScriptInterface( Context c ) {
mContext = c;
}
public void DoSomething( String dataToPrint )
{
.....
}
}
I read that the problem might be proguard. So I updated the proguard rules file :
-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 *;
}
It didn't help though... in the chrome debugger, since I put in console the ajaxHandler object and the DoSomething method, I can see the ajaxHandler object as Object {}
but it's empty, and the method DoSomething is undefined
Interface class
public class JavaScriptInterface
{
Context mContext;
JavaScriptInterface( Context c ) {
mContext = c;
}
@JavascriptInterface //add this
public void DoSomething( String dataToPrint )
{
.....
}
}
In proGuard.pro file
-keep public class com.example.testapp.MainActivity$JavaScriptInterface
-keep public class * implements com.example.testapp.MainActivity$JavaScriptInterface
-keepclassmembers class * implements com.example.testapp.MainActivity$JavaScriptInterface{
<methods>;
}
-keepattributes *Annotation*
Use $ sign not . to get inner interface class name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With