Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addJavascriptInterface not working #15

Open
xli2012 opened this issue Jan 16, 2013 · 4 comments
Open

addJavascriptInterface not working #15

xli2012 opened this issue Jan 16, 2013 · 4 comments

Comments

@xli2012
Copy link

xli2012 commented Jan 16, 2013

Hi,

I followed your instruction and built the sample phonegap app, but it doesn't work plus the log shows:
E/Web Console( 1285): Uncaught TypeError: Object [object Object] has no method 'getInstance' at file:///android_asset/www/js/websocket.js:35

The main class looks like this:
public class Grunt extends DroidGap
{
@OverRide
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
init();
final WebSocketFactory factory = new WebSocketFactory(appView);
appView.addJavascriptInterface(factory, "WebSocketFactory");
loadUrl("file:///android_asset/www/websocket.html");
}
}
I have tried to swap the lines, calling init(), etc., none works.
Do you have a thought? I have googled the whole night and couldn't find a solution, please give me some light!

Thanks!

@anismiles
Copy link
Owner

Current project was designed to work with Phonegap-0.9 version. Probably you are using some other version, and that's why you are seeing this problem. I didn't get a chance to update this project for newer Phonegap versions. Will do it whenever I have some time.

  • Animesh

@naoufalmed
Copy link

Hi,

Maybe you have already figured it out how to solve (or work around) this issue, but this comment can help others who might get into the same issue.

This issue happens if your target API is Jelly Beans MR1 or higher. If this is the case, the WebSocketFactory class should be updated to follow the new guidelines of the Android API about the usage of the addJavascriptInterface() method. If you can live with targeting lower API levels (e.g. level 15) then changing the API target in AndroidManifest.xml to lower API levels will allow you to continue using this WebSocket library without modification.

@vivekdpk
Copy link

vivekdpk commented May 3, 2013

This issue happens if your target API is Jelly Beans MR1 or higher. If this is the case, the WebSocketFactory class should be updated to follow the new guidelines of the Android API about the usage of the addJavascriptInterface() method.

if i want to work with api 17. then in that case what should i have to do? how will i update WebSocketFactory class . Or may be some other trick or idea?

@naoufalmed
Copy link

I didn't try it myself, as I don't need to work with the newest APIs, but maybe you might find some guidelines in the Android API at: http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object,%20java.lang.String)
I hope this can help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants