Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@JavascriptInterface cannot be resolved

I'm working with Android to make a webpage interact with my app. As such, I've gone through the documentation and tutorials and ended up coming up with this site. In it, the developers list that you should include @JavascriptInterface before any function you wish to be accessible by the WebView and that without it, Jelly Bean won't recognize the function.

My problem is that when I put that in, I get an error saying:

@JavascriptInterface cannot be resolved to a type

Without it, my code compiles and works fine, but I want Jelly Bean compatibility. I'm currently working on Android 1.6 as a base, so does it just not have @JavascriptInterface? Is that a Jelly Bean specific thing, meaning I'll have to make a program specifically for Jelly Bean? Any help would be greatly appreciated. Here is my complete interface class:

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();
    }

}
like image 399
user1982687 Avatar asked Jan 16 '13 07:01

user1982687


1 Answers

@JavascriptInterface is introduced in JellyBean.

You need to set the Project Build Target to API Level 17

From Eclipse IDE, go to Project->Properties. Select Android and set the target

The APK will work on older versions of android.

like image 101
Tarak Avatar answered Sep 28 '22 05:09

Tarak