繁体   English   中英

@JavascriptInterface无法解析

[英]@JavascriptInterface cannot be resolved

我正在与Android合作,使网页与我的应用互动。 因此,我已经完成了文档和教程,最终提出了这个网站 在其中,开发人员列出您应该在WebView可以访问的任何函数之前包含@JavascriptInterface ,如果没有它,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();
    }

}

@JavascriptInterface是在JellyBean中引入的。

您需要将项目构建目标设置为API级别17

从Eclipse IDE,转到Project->Properties 选择Android并设置目标

APK将适用于旧版本的Android。

你需要添加这个:

import android.webkit.JavascriptInterface;

在这里查看样本:

适用于Android Studio的用户的步骤:

  1. 检查build.gradle中minSdkVersion是否为17或更高
  2. 添加import android.webkit.JavascriptInterface;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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