Kirbs
Kirbs

Reputation: 43

Getting Socket.io to work in Android Webview

I am trying to use socket.io inside an Android Webview, inside a native Android app. The Android activity file has been updated with;

webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("file:///android_asset/www/public/index.html");

My problem is loading the socket.io.js libraries from the index.html:

<script src="http://mydomain:port/socket.io/socket.io.js"></script>

The error I get during the rendering of the webview is:

XMLHttpRequest cannot load http://mydomain:port/socket.io... Origin null is not allowed by Access-Control-Allow-Origin.

I am using a node.js/express server to try and serve the libraries and thought I had configured this to accept cross-origin-resource-sharing (CORS) by setting

    res.header('Access-Control-Allow-Origin', "*");

Now I am completely stuck! Can anybody recommend a way forward to get socket.io working in this configuration?

Cheers,

Kirbs

Upvotes: 4

Views: 2963

Answers (1)

fhamicode
fhamicode

Reputation: 2518

why not run service socket.io at activity, try my answer at this

singleton service socket.io

I using socket-io.java client library from github

Gottox

Upvotes: 1

Related Questions