Using SIGNALR Push service on Android implementation signala_android

Source: Internet
Author: User

Since my version has a minimum of 2.2, so only the source down to change their own, if you think too much can be compiled into a jar reference, I am not very familiar with Java, if this version of the error also please point out, this figure shows the Android 2.2 and 4.0 version.

Chat_hub Code:

<?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:

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.o 
    Ncreate (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 the 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 () {@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 ();

 } 
}

SIGNALR server-side code reference HTTP://WWW.ASP.NET/SIGNALR to write

More usage Reference Signala official documents

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.