'Smack'에 해당되는 글 4건

  1. 2010.10.28 Smack patch (1)
  2. 2010.10.28 Android Smack example (5)
  3. 2010.10.06 XMPP opensource library SMACK #2 - Processing Incoming Packets (1)
  4. 2010.10.06 XMPP opensource library SMACK #1 (1)
Android/XMPP2010.10.28 21:11


http://blog.jayway.com/2008/11/21/give-back-my-xmpp-in-android/

SASL 관련 XMPPConnection클래스의 버그를 수정한 패치가 올려져 있다.

아래와 같은 에러 발생시 이 패치가 유용할 것이다.

10-28 19:40:09.640: ERROR/AndroidRuntime(2342): java.lang.VerifyError: org.jivesoftware.smack.sasl.SASLMechanism
10-28 19:40:09.640: ERROR/AndroidRuntime(2342):     at java.lang.Class.getDeclaredConstructors(Native Method)
10-28 19:40:09.640: ERROR/AndroidRuntime(2342):     at java.lang.Class.getConstructor(Class.java:477)
10-28 19:40:09.640: ERROR/AndroidRuntime(2342):     at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:303)

10-28 19:40:09.640: ERROR/AndroidRuntime(2342):     at
org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:395)
10-28 19:40:09.640: ERROR/AndroidRuntime(2342):     at
org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:349)
10-28 19:40:09.640: ERROR/AndroidRuntime(2342):     at com.yamaia.mobilebridge.delivery.PushService$LoginThread.run(PushService.java:404)
10-28 19:40:09.640: ERROR/AndroidRuntime(2342):     at java.lang.Thread.run(Thread.java:1102)



신고
Posted by 삼스
Android/XMPP2010.10.28 19:47


http://davanum.wordpress.com/2007/12/31/android-just-use-smack-api-for-xmpp/


Android – Just Use Smack API For XMPP

Filed under: Uncategorized — Davanum Srinivas @ 9:36 am

OUTDATED SAMPLE – Updated code is here:


http://davanum.wordpress.com/2008/12/29/updated-xmpp-client-for-android/

Using Smack XMPP API From Android

Once you get tired of the limitations of android’s built-in IMProvider and the corresponding API – IXmppSession and IXmppService, try the sample below. Inside the source/binary zip (bottom of this article) you will find a smack.jar that works with android. To build the jar yourself, You can download the Smack 3.0.4 sources from here and apply the patch here.

Here Is A Screen Shot Of The XMPP Settings Dialog.

1

Notes



  • For GTalk, use “gtalk.google.com” as host with port 5222. The service name is “gmail.com”

  • Don’t add “@gmail.com” in the user name, just the id will do

Here’s The Code For The Settings Dialog

01 package org.apache.android.xmpp;
02  
03 import android.app.Dialog;
04 import android.util.Log;
05 import android.view.View;
06 import android.widget.Button;
07 import android.widget.EditText;
08 import org.jivesoftware.smack.ConnectionConfiguration;
09 import org.jivesoftware.smack.XMPPConnection;
10 import org.jivesoftware.smack.XMPPException;
11 import org.jivesoftware.smack.packet.Presence;
12  
13 /**
14  * Gather the xmpp settings and create an XMPPConnection
15  */
16 public class SettingsDialog extends Dialog implements android.view.View.OnClickListener {
17     private XMPPClient xmppClient;
18  
19     public SettingsDialog(XMPPClient xmppClient) {
20         super(xmppClient);
21         this.xmppClient = xmppClient;
22     }
23  
24     protected void onStart() {
25         super.onStart();
26         setContentView(R.layout.settings);
27         getWindow().setFlags(44);
28         setTitle("XMPP Settings");
29         Button ok = (Button) findViewById(R.id.ok);
30         ok.setOnClickListener(this);
31     }
32  
33     public void onClick(View v) {
34         String host = getText(R.id.host);
35         String port = getText(R.id.port);
36         String service = getText(R.id.service);
37         String username = getText(R.id.userid);
38         String password = getText(R.id.password);
39  
40         // Create a connection
41         ConnectionConfiguration connConfig =
42                 new ConnectionConfiguration(host, Integer.parseInt(port), service);
43         XMPPConnection connection = new XMPPConnection(connConfig);
44  
45         try {
46             connection.connect();
47             Log.i("XMPPClient""[SettingsDialog] Connected to " + connection.getHost());
48         catch (XMPPException ex) {
49             Log.e("XMPPClient""[SettingsDialog] Failed to connect to " + connection.getHost());
50             xmppClient.setConnection(null);
51         }
52         try {
53             connection.login(username, password);
54             Log.i("XMPPClient""Logged in as " + connection.getUser());
55  
56             // Set the status to available
57             Presence presence = new Presence(Presence.Type.available);
58             connection.sendPacket(presence);
59             xmppClient.setConnection(connection);
60         catch (XMPPException ex) {
61             Log.e("XMPPClient""[SettingsDialog] Failed to log in as " + username);
62             xmppClient.setConnection(null);
63         }
64         dismiss();
65     }
66  
67     private String getText(int id) {
68         EditText widget = (EditText) this.findViewById(id);
69         return widget.getText().toString();
70     }
71 }

Here Is A Screen Shot Of The Main Window.

1

Notes



  • In the Recipient field, make sure you add the “@gmail.com”, not just the user id

Here’s The Code For The Main Activity

001