Signala is written by a foreigner to implement the. NET end push message to the Android implementation, supported version Android 2.3 or above, Since my version of the lowest is 2.2, so only the source down their own change, if you think too much can be compiled into a jar of their own reference, I am not very familiar with Java, if there are errors in this version also please point out, this figure shows the version of Android 2.2 and 4.0.
Chat_hub Code:
[HTML]View Plaincopyprint?
- <? XML version= "1.0" encoding="Utf-8"?>
- <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <EditText
- android:id="@+id/chat_text"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_margin="20DP"
- android:gravity="Top"
- android:inputtype="Textmultiline"
- android:text="" />
- </linearlayout>
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "vertical" > <edittext android:id= "@+id/chat_text" android:layout_width= "Match_ Parent " android:layout_height=" match_parent " android:layout_margin=" 20DP " android:gravity=" Top " android:inputtype= "Textmultiline" android:text= ""/></linearlayout>
Chathub.java Code:
[Java]View Plaincopyprint?
- Package com.loan.zhironghuimobile;
- Import Org.json.JSONArray;
- Import com.zsoft.SignalA.Hubs.HubConnection;
- Import Com.zsoft.SignalA.Hubs.HubOnDataCallback;
- Import Com.zsoft.SignalA.Hubs.IHubProxy;
- Import Com.zsoft.SignalA.Transport.StateBase;
- Import Com.zsoft.SignalA.Transport.Longpolling.LongPollingTransport;
- Import android.app.Activity;
- Import android.content.OperationApplicationException;
- Import Android.os.Bundle;
- Import Android.widget.EditText;
- Public class Chathub extends Activity {
- Private final static String hub_url="Http://192.168.1.200:82/signalr/hubs";
- @Override
- protected void OnCreate (Bundle savedinstancestate) {
- //TODO auto-generated method stub
- super.oncreate (savedinstancestate);
- Setcontentview (R.layout.chat_hub);
- BeginConnect ();
- }
- /**
- * Hub Link
- */
- Private hubconnection conn=new Hubconnection (Hub_url, this , new Longpollingtransport ()) {
- @Override
- public void OnError (Exception Exception) {
- }
- @Override
- public void OnMessage (String message) {
- }
- @Override
- public void onstatechanged (Statebase oldstate, Statebase newstate) {
- }
- };
- /**
- * Hub Agent Panderman 2013-10-25
- */
- private Ihubproxy hub = null;
- /**
- * Launch push service Panderman 2013-10-25
- */
- private void BeginConnect () {
- try {
- Hub=conn. Createhubproxy ("Chathub");
- } catch (Operationapplicationexception e) {
- E.printstacktrace ();
- }
- Hub. On ("Addnewmessagetopage", new Hubondatacallback ()
- {
- @Override
- public void onreceived (Jsonarray args) {
- EditText chattext= (EditText) Findviewbyid (R.id.chat_text);
- //chattext.settext (args.tostring ());
- For (int i=0; I<args.length (); i++)
- {
- Chattext.append (Args.opt (i). toString ());
- }
- }
- });
- Conn. Start ();
- }
- }
Package Com.loan.zhironghuimobile;import Org.json.jsonarray;import Com.zsoft.signala.hubs.hubconnection;import Com.zsoft.signala.hubs.hubondatacallback;import Com.zsoft.signala.hubs.ihubproxy;import Com.zsoft.signala.transport.statebase;import Com.zsoft.SignalA.Transport.Longpolling.LongPollingTransport; Import Android.app.activity;import Android.content.operationapplicationexception;import Android.os.Bundle;import Android.widget.edittext;public class Chathub extends Activity {private final static String hub_url= "/http/ 192.168.1.200:82/signalr/hubs "; @Overrideprotected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stubsuper.oncreate (Savedinstancestate); Setcontentview (R.layout.chat_hub); BeginConnect ();} /** * HUB link */private hubconnection conn=new hubconnection (Hub_url, this, New Longpollingtransport ()) {@Override public void OnError (Exception Exception) {} @Override public void OnMessage (String message) { } @OveRride public void onstatechanged (Statebase oldstate, Statebase newstate) {}}; /** * Hub Agent Panderman 2013-10-25 */private Ihubproxy hub = null; /** * Open Push service Panderman 2013-10-25 */private void BeginConnect () {try {hub=conn. Createhubproxy ("Chathub");} catch (Operationapplicationexception e) {e.printstacktrace ();} Hub. On ("Addnewmessagetopage", new Hubondatacallback () {@Overridepublic void onreceived (Jsonarray args) {EditText chattext= (EditText) Findviewbyid (R.id.chat_text);//chattext.settext (args.tostring ()); for (int i=0; i<args.length (); i++) { Chattext.append (Args.opt (i). toString ());}}); Conn. Start (); }}
SIGNALR server-side code reference HTTP://WWW.ASP.NET/SIGNALR to write
Signala modified after the source download
More usage Reference Signala official documentation