我正在与Android合作,使网页与我的应用互动.因此,我已经完成了文档和教程,最终提出了这个网站.在其中,开发人员列出了您@JavascriptInterface希望WebView可以访问的任何函数之前应该包含的内容,如果没有它,Jelly Bean将无法识别该函数.
我的问题是,当我把它放进去时,我得到一个错误说:
@JavascriptInterface无法解析为某个类型
没有它,我的代码编译和工作正常,但我想要Jelly Bean兼容性.我目前正在开发Android 1.6作为基础,所以它没有@JavascriptInterface?这是Jelly Bean特有的东西,这意味着我必须专门为Jelly Bean制作一个程序吗?任何帮助将不胜感激.这是我完整的接口类:
import android.content.Context;
public class WebAppInterface{
Context mContext;
/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
//needed for jelly bean
@JavascriptInterface
public void turnOff() {
MyAlarmPopup.turnOff();
}
}
Run Code Online (Sandbox Code Playgroud)