The first few days of the project encountered the whole problem, run on the android2.2, OK, wood has problems. Got 4.4 on the test, no response in WebView.
This is because Google has made a bug fix to WebView after android4.2.x. Only JS is allowed to invoke the @javascriptinterface annotated method in Java. Look at the online solution, found that said is not very clear, here I still put this solution to the ultimate summary to write it, later people less detours it.
It is believed that the apes have searched many of these solutions:
As mentioned above, you need to add @javascriptinterface annotations before your JS call method. But some people's code would say that the class could not be found and that a class would need to be created. And then I'll probably search the same class support library for this annotation as I do. Oh oh ... Start a detour.
In fact, there is already this class in android4.2. We just need to change the build SDK in the properties to 4.2 of 17. If you don't have a 17 SDK on your computer, well, that's the problem. Solve yourself!
Seemingly no code, no convincing. Wow, symbolic addition of a piece of code (and then egg):
Class Ccl{context context, @SuppressLint ("Javascriptinterface") public Ccl (context context) {This.context = context;} @JavascriptInterfacepublic void Showmap (String jingdu,string weidu) {judgeinstall (Jingdu,weidu);}}
Javascript:ccl.showMap (' \ ' +jingdu+\ ' ', ' \ ' +weidu+\ '); \ "
Ok!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android 4.4 js Call WebView Activity method record