2014-05-07 5 views
1

Je suis en train de se connecter à mon serveur Openfire en cours d'exécution avec ce code:Se connecter au serveur Openfire via Android

public static final String HOST = "ipofmyserver"; 
public static final int PORT = 9122; // set by me 
//public static final String SERVICE = "gmail.com"; not used because i don't know what it refers to 

ConnectionConfiguration connConfig = new ConnectionConfiguration(HOST, PORT); 
XMPPConnection connection = new XMPPConnection(connConfig); 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    //Connect to the server 
    try { 
     connection.connect(); 
    } catch (XMPPException e) { 
     connection = null; 
     //Unable to connect to server 
    } 

    //Most servers require you to login before performing other tasks. 
    if (connection != null) { 
     try { 
      connection.login("xxxx", "xxxx"); 
     } catch (XMPPException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

LogCat

http://pastebin.com/9fcbzqgj

EDIT

j'ai ajouté une exception exceptionininitializer et maintenant il ne plante pas, mais maintenant je reçois:

05-07 03:27:55.734 3184-3184/xxx.xxx.xxxxxE/dalvikvm﹕ Could not find class 'javax.naming.directory.InitialDirContext', referenced from method org.jivesoftware.smack.util.dns.JavaxResolver.<clinit> 

MISE À JOUR

j'ai lu que Android ne permet l'accès à certaines des classes standard, qui sont JRE dans cette liste blanche https://developers.google.com/appengine/docs/java/jrewhitelist

so .. Que dois-je faire si je veux utiliser l'api Smack? Je ne peux pas? J'ai essayé avec aSmack, mais il doit être compilé sur linux ou mac, et j'ai seulement obtenu des fenêtres

+0

double possible (http://stackoverflow.com/questions/23507724/how -à-implémenter-xmpp-chat-dans-une-android-app) – Flow

Répondre

0

S'il vous plaît si vous utilisez l'API smack, vous devez également utiliser le fichier xpp.jar dans votre projet. J'ai également fait face au même problème et résolu ce problème avec cette API.

Voici le lien pour cette API. Xpp download link

0

en studio Android gradle, les dépendances de travail pour moi: [? Comment mettre en œuvre dans le chat XMPP une application android]

dependencies { 
    compile 'org.igniterealtime.smack:smack-android:4.1.1' 
    compile 'org.igniterealtime.smack:smack-android-extensions:4.1.1' 
    compile 'org.igniterealtime.smack:smack-core:4.1.1' 
    compile 'org.igniterealtime.smack:smack-tcp:4.1.1' 
    compile 'org.igniterealtime.smack:smack-extensions:4.1.1' 
    compile 'org.igniterealtime.smack:smack-experimental:4.1.1' 
    compile 'org.igniterealtime.smack:smack-resolver-minidns:4.1.1' 
    compile 'org.igniterealtime.smack:smack-sasl-provided:4.1.1' 
    compile 'org.igniterealtime.smack:smack-im:4.1.1' 
    compile 'org.jxmpp:jxmpp-core:0.4.2-beta1' 
    compile 'org.jxmpp:jxmpp-util-cache:0.4.2-beta1' 
    compile 'de.measite.minidns:minidns:0.1.1' 
    compile 'com.android.support:appcompat-v7:22.2.0' 
} 
Questions connexes