Android4.2对webview中Javascript接口声明进行了修改,Android 4.2以上版本调用Javascript接口失败的解决方法是在方法之前使用声明@JavascriptInterface。
.addJavascriptInterface(new Object()
{
@JavascriptInterface
public void download(int bookId)
{
bid = String.valueOf(bookId);
downLoad.show();
}
下面是我打的支持包,直接拷贝在libs文件夹下就能使用.
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.