SIGNALR Push service on Android implementation Signala

Source: Internet
Author: User

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?
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6. <EditText
  7. android:id="@+id/chat_text"
  8. android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. android:layout_margin="20DP"
  11. android:gravity="Top"
  12. android:inputtype="Textmultiline"
  13. android:text="" />
  14. </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?
  1. Package com.loan.zhironghuimobile;
  2. Import Org.json.JSONArray;
  3. Import com.zsoft.SignalA.Hubs.HubConnection;
  4. Import Com.zsoft.SignalA.Hubs.HubOnDataCallback;
  5. Import Com.zsoft.SignalA.Hubs.IHubProxy;
  6. Import Com.zsoft.SignalA.Transport.StateBase;
  7. Import Com.zsoft.SignalA.Transport.Longpolling.LongPollingTransport;
  8. Import android.app.Activity;
  9. Import android.content.OperationApplicationException;
  10. Import Android.os.Bundle;
  11. Import Android.widget.EditText;
  12. Public class Chathub extends Activity {
  13. Private final static String hub_url="Http://192.168.1.200:82/signalr/hubs";
  14. @Override
  15. protected void OnCreate (Bundle savedinstancestate) {
  16. //TODO auto-generated method stub
  17. super.oncreate (savedinstancestate);
  18. Setcontentview (R.layout.chat_hub);
  19. BeginConnect ();
  20. }
  21. /**
  22. * Hub Link
  23. */
  24. Private hubconnection conn=new Hubconnection (Hub_url, this , new Longpollingtransport ()) {
  25. @Override
  26. public void OnError (Exception Exception) {
  27. }
  28. @Override
  29. public void OnMessage (String message) {
  30. }
  31. @Override
  32. public void onstatechanged (Statebase oldstate, Statebase newstate) {
  33. }
  34. };
  35. /**
  36. * Hub Agent Panderman 2013-10-25
  37. */
  38. private Ihubproxy hub = null;
  39. /**
  40. * Launch push service Panderman 2013-10-25
  41. */
  42. private void BeginConnect () {
  43. try {
  44. Hub=conn.  Createhubproxy ("Chathub");
  45. } catch (Operationapplicationexception e) {
  46. E.printstacktrace ();
  47. }
  48. Hub. On ("Addnewmessagetopage", new Hubondatacallback ()
  49. {
  50. @Override
  51. public void onreceived (Jsonarray args) {
  52. EditText chattext= (EditText) Findviewbyid (R.id.chat_text);
  53. //chattext.settext (args.tostring ());
  54. For (int i=0; I<args.length (); i++)
  55. {
  56. Chattext.append (Args.opt (i). toString ());
  57. }
  58. }
  59. });
  60. Conn. Start ();
  61. }
  62. }
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.