简体   繁体   中英

JavaScriptInterface() not working in JellyBean

I just had a software update of my Galaxy Tab2 from ICS to Jelly Bean. I was working on an app where I was loading some Html with some js files, calling some functions written itself in Javascript files, everything was working fine, completely tested on Android devices (Phones and Tablets(4.0.1)), but after the update on tablet, it stopped working.

While calling js function using JavaScriptInterface() , I am not getting any response in return. Any ideas?

This must be the problem:

For applications targeted to API level JELLY_BEAN_MR1 and above, only public methods that are annotated with JavascriptInterface can be accessed from JavaScript.

Documentation update here . I also see people reporting that they had to fiddle with proguard , but I haven't stumbled upon that myself.

Just had exactly the same issue and Vytautas is correct. It was really frustrating. Everything in my project was working fine on Jelly Bean API16 and then I tried it on API17 and it was crippled. Just add

@JavascriptInterface

public void showToast(String toast)  {
    // show toast ...
}

Including this in a project that also supports previous API versions will require that you select a build target of API 17 (or higher) in your project settings.

  • From the Project menu click on Properties
  • Click on Android in the list on the left.
  • Check an API Level of 17 (I clicked on GOOGLE APIs 4.2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM