Android 4.4 js Call WebView Activity method record

Source: Internet
Author: User

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

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.