Skip to content

IndrekV/PhoneGap-Android-HTML5-WebSocket

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Android HTML5 WebSocket

A Java library that makes a WebSocket object available for projects that uses a WebView (like PhoneGap project)

Usage

  • copy the java-src contents into the src folder of your project.
  • add import com.freakdev.phonegap.*; to the imports of your main java file
  • also add these two lines inside the onCreate function, after the loadUrl
   WebSocketFactory wsFactory = new WebSocketFactory(appView);
   appView.addJavascriptInterface(wsFactory, "WebSocketFactory");
  • copy websocket.js to your assets/www folder
  • edit your index.html to include the websocket.js
  • in your javascript, create a new WebSocket, and overload its methods 'onopen','onmessage','onerror','onclose';
var ws = new WebSocket("ws://192.168.13.37:1337/");

ws.onopen = function()
{
	ws.send("Message to send");
	alert("Message is sent...");
};
ws.onerror = function (e) 
{ 
	alert("Error...");
};
ws.onmessage = function (evt) 
{ 
	var received_msg = evt.data;
	alert("Message is received...");
};
ws.onclose = function()
{ 
	alert("Connection is closed..."); 
};

About

a little java implementation of missing WebSocket form Android webview

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 92.5%
  • JavaScript 7.5%