I am writing a chat client in Android using the XMPP protocol. I used asmack.jar as provided by http://asmack.freakempire.de/ . The implementation works in plain Java (using smack.jar), which I tested. But on Android, I can only send messages to another client (it uses pidgin) and cannot receive messages from it. The application successfully connects to the server, registers and appears on the network, but simply does not receive any message.
My processMessage() never called and does not execute chatCreated() when a message is sent to my client.
My Activity class:
package com.example.basicchat; import org.jivesoftware.smack.AndroidConnectionConfiguration; import org.jivesoftware.smack.Chat; import org.jivesoftware.smack.ChatManager; import org.jivesoftware.smack.ChatManagerListener; import org.jivesoftware.smack.ConnectionListener; import org.jivesoftware.smack.MessageListener; import org.jivesoftware.smack.SmackAndroid; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.Message; import android.app.Activity; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SmackAndroid.init(this); MainActivity2 xmppClient= new MainActivity2("jabber.org", 5222); try { xmppClient.login(); } catch (XMPPException e) {
}
Manifest file:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.basicchat" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.basicchat.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
source share