FileDocCategorySizeDatePackage
XmppDataMessageSender.javaAPI DocGoogle Android v1.5 Example6711Sun Nov 11 13:01:04 GMT 2007com.google.android.samples.app

XmppDataMessageSender

public class XmppDataMessageSender extends android.app.Activity

Example of using the XmppService{@link com.google.android.xmppService.IXmppService} to receive peer to peer data messages. This demonstrates how to use the XmppService to receive data to/from another Android device.

Demo

App/Service/Xmpp Data Message Receiver

Source files

src/com/google/android/samples/app/XmppDataMessageSender.java The XmppService data message Sender
src/com/google/android/samples/app/XmppDataMessageReceiver.java The XmppService data message receiver
res/layout/xmpp_data_message_sender.xml Defines contents of the screen for the Xmpp message sender

Fields Summary
private static final String
LOG_TAG
com.google.android.xmppService.IXmppSession
mXmppSession
android.widget.EditText
mUsernameField
android.widget.Button
mSendButton
private android.content.ServiceConnection
mConnection
private View.OnClickListener
mOnClickListener
Constructors Summary
Methods Summary
private voidbindXmppService()

        bindService((new Intent()).setComponent(
                com.google.android.xmppService.XmppConstants.XMPP_SERVICE_COMPONENT),
                null, mConnection, 0);
    
private android.content.IntentgetIntentToSend()

        Intent intent = new Intent(XmppDataMessageReceiver.ACTION);
        intent.putExtra("poke", "Hi, I am Sam.");
        intent.putExtra("question", "would you like to eat green eggs and ham?");

        return intent;
    
private booleanisValidUsername(java.lang.String username)

        if (TextUtils.isEmpty(username)) {
            return false;
        }

        if (username.indexOf('@") == -1) {
            return false;
        }

        return true;
    
protected voidonCreate(android.os.Bundle icicle)


    
        
        super.onCreate(icicle);

        setContentView(R.layout.xmpp_data_message_sender);

        mUsernameField = (EditText)findViewById(R.id.username);
        mUsernameField.setOnClickListener(mOnClickListener);
        mUsernameField.requestFocus();

        mSendButton = (Button)findViewById(R.id.send);
        mSendButton.setOnClickListener(mOnClickListener);
        mSendButton.setEnabled(false);

        bindXmppService();
    
protected voidonDestroy()

        super.onDestroy();
        unbindService(mConnection);
    
private voidshowMessage(java.lang.CharSequence msg)

        NotificationManager nm = (NotificationManager)getSystemService(
                Context.NOTIFICATION_SERVICE);

        nm.notifyWithText(123, msg,  NotificationManager.LENGTH_LONG, null);