Javascript interface not working with android 4.2
And, if you are using Proguard, remember to add this
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
-keepattributes JavascriptInterface
-keep public class com.mypackage.MyClass$MyJavaScriptInterface
-keep public class * implements com.mypackage.MyClass$MyJavaScriptInterface
-keepclassmembers class com.mypackage.MyClass$MyJavaScriptInterface {
<methods>;
}
If it's still not OK, add this
-keepattributes *Annotation*
Note: your MyJavaScriptInterface must be Public class
Ref#: Android Proguard Javascript Interface Fail
Android 4.2.1, WebView and javascript interface breaks
From the Android 4.2 documentation:
Caution: If you've set your targetSdkVersion to 17 or higher, you must add the @JavascriptInterface annotation to any method that you want available your web page code (the method must also be public). If you do not provide the annotation, then the method will not accessible by your web page when running on Android 4.2 or higher.
JavascriptInterface not working with proguard on Android 4.2
I have found the solution, I just have to tell proguard to keep the JavascriptInterface
annotation. I added this to my proguard configuration to make it work:
-keepattributes JavascriptInterface
JavaScript Interface to a Browser not working in 4.2.2
If your android:targetSdkVersion
is set to 17 or higher, you need to add the @JavascriptInterface
annotation to getSomeData()
, as is described in the documentation.
Javascript to native Android calls do not work on Android 4.2
You might try building for API 17, but setting the minimum version lower. Something like <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17"/>
Android Proguard Javascript Interface Fail
If MyJavaScriptInterface is an inner class of MyClass, ProGuard expects a fully qualified name com.mypackage.MyClass$MyJavaScriptInterface
. The naming convention with $
is used in the compiled class files on which ProGuard operates. Note that ProGuard mentions class names in the configuration that it can't find in the input jar, suggesting that these names may have been misspelled.
Related Topics
CSS Textarea That Expands as You Type Text
Detect Browser Character Support in JavaScript
Set the Default Save as Name for a an <Embed> or <Iframe> That Uses a Blob
Cross Browser Rgba Transparent Background While Keeping Content (Text & Images) Non-Transparent
How to Customize Ant.Design Styles
D3: .Transition() Not Working with Events
Fading Visibility of Element Using Jquery
Flip Vertically a Background-Image Every Time It Repeat-Y
Partial Password Masking on Input Field
Blur Img's & Div's in HTML Using CSS
Check If Window Is Already Open Window.Open
Using JavaScript to Compare Two Input Numbers in HTML
How to Make a Div Always Float on the Screen in Top Right Corner
Get Final Size of Background Image
Use CSS (And Maybe JavaScript) to Make an Element Be Square (Or Maintain a Specific Aspect Ratio)