Sending XMPP messages in Android – Standalone sample (Ant build.xml/intellij project)
Set up your XMPP Settings under Dev Tools
Download the XMPPSender.zip and install the app
adb install XMPPSender.apk
The Zip has an Ant build.xml that you can use to build the complete project.
Run the app, enter your friend’s gtalk email and the text and press send
Here’s the code that gets a XMPP session
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
// This is called when the connection with the XmppService has been
// established, giving us the service object we can use to
// interact with the service. We are communicating with our
// service through an IDL interface, so get a client-side
// representation of that from the raw service object.
IXmppService xmppService = IXmppService.Stub.asInterface(service);
try {
mXmppSession = xmppService.getDefaultSession();
if (mXmppSession == null) {
// this should not happen.
logMessage(getText(R.string.xmpp_session_not_found));
return;
}
} catch (DeadObjectException ex) {
Log.e(LOG_TAG, "caught " + ex);
logMessage(getText(R.string.found_stale_xmpp_service));
}
mSendButton.setEnabled(true);
}
public void onServiceDisconnected(ComponentName className) {
// This is called when the connection with the service has been
// unexpectedly disconnected -- that is, its process crashed.
mXmppSession = null;
mSendButton.setEnabled(false);
}
};
Here’s the code that actually sends the message
private View.OnClickListener mOnClickListener = new View.OnClickListener() {
public void onClick(View v) {
if (v == mUsernameField) {
mSendButton.requestFocus();
} else {
// use XmppService to send data message to someone
String username = mUsernameField.getText().toString();
if (!isValidUsername(username)) {
logMessage(getText(R.string.invalid_username));
return;
}
if (mXmppSession == null) {
logMessage(getText(R.string.xmpp_service_not_connected));
return;
}
try {
mXmppSession.sendTextMessage(username, 0,
mTextField.getText().toString());
} catch (DeadObjectException ex) {
Log.e(LOG_TAG, "caught " + ex);
logMessage(getText(R.string.found_stale_xmpp_service));
mXmppSession = null;
bindXmppService();
}
}
}
};


Great stuff! They are even using Java code. Must buy one…
Mark
November 15, 2007 at 12:33 pm
Yes, fantastic job. I like the fact that you are not dependent on Eclipse IDE. Thank You
Steve
November 15, 2007 at 6:28 pm
[...] Sending XMPP messages in Android – Standalone sample (Ant build.xml/intellij project) Set up your XMPP Settings under Dev Tools [image] Download the XMPPSender.zip and install the app adb install […] [...]
Top Posts « WordPress.com
November 15, 2007 at 7:01 pm
hiii can u explain a little bit more???
hw can we use Xmpp?
Wat do we need ??
please do help.
regards
Ck
chakradhar
November 17, 2007 at 2:59 pm
[...] Простенький пример, как отправить сообщение через XMPP. Исходный код и авторы примера находятся тут: http://davanum.wordpress.com [...]
Googlephone X Team » Blog Archive » Отправка XMPP сообщения
November 20, 2007 at 12:16 am
Thnks a lot for the information.. Hey 1 doubt
sendTextMessage () will send a message to a gtalk user, but if we get a reply for the message we send, will there be an event fire’d. Where do we get it? can you please please post an example for it
thanks a lot
Amith GC
November 20, 2007 at 7:39 am
[...] vous laisse consulter son billet sur le [...]
Android After All » Envoyer du texte via XMPP
November 21, 2007 at 11:06 am
[...] “voir le code”, c’est par là [...]
Android France » Archive du blog » Comment envoyer des messages XMPP avec Android ?
November 21, 2007 at 12:23 pm
[...] http://davanum.wordpress.com/2007/11/14/sending-xmpp-messages-in-android-standalone-sample-ant-build... (Celui-ci montre comment envoyer un message par le protocole Xmpp) [...]
Helyx Weblog » Blog Archive » Première contributions et démos intéressantes pour Android
November 21, 2007 at 4:05 pm
great example, thanks!
milan
November 22, 2007 at 10:34 am
I try to receive messages as well but no success, could you post another example, if you know how to do it, please,
milan
November 23, 2007 at 3:20 am
[...] and go into Dev Tools/XMPP Settings and add a valid gmail account, then it works as expected, see here. This doesn’t seem to allow general peer to peer connections between apps and in particular [...]
Wink Saville’s Blog » Android -Xmpp
December 21, 2007 at 4:54 pm
[...] with sending XMPP message from andoird have a look at the samples in the google documentation or this post.To handle the received messages on the server end we will use a custom smack extension. The code [...]
Android on Smack « The Tech Gene, Craig Baker
January 3, 2008 at 3:41 am
Where is the code?
Can someone suggest?
Thanks
trackback
October 25, 2008 at 10:43 pm
Hi.. EveryOne
I cant download the zip file.. any body have please send to me..
Thanks
Bose Pandian
February 10, 2009 at 9:54 am