In my MainActivity, I have the following code:
webView.addJavascriptInterface( new JavaScriptInterface( this ), "ajaxHandler" );
....
public class JavaScriptInterface
{
Context mContext;
JavaScriptInterface( Context c ) {
mContext = c;
}
public void DoSomething( String dataToPrint )
{
.....
}
}
I've encountered an issue where the ajaxHandler object is empty and the DoSomething method is undefined. I've heard that the problem might be related to Proguard. To address this, I've 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 *;
}
However, the issue persists. In the Chrome debugger, when I log the ajaxHandler object and the DoSomething method in the console, I see the ajaxHandler object as Object {}
but it's empty, and the method DoSomething is undefined