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

XmppDataMessageReceiver

public class XmppDataMessageReceiver extends android.content.IntentReceiver

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/XmppDataMessageReceiver.java The XmppService data message receiver
src/com/google/android/samples/app/XmppDataMessageSender.java The XmppService data message Sender

Fields Summary
private static final String
LOG_TAG
static final String
ACTION
Constructors Summary
Methods Summary
private voidappendData(java.lang.StringBuilder buf, java.lang.String key, java.lang.String value)

        buf.append(", ");
        buf.append(key);
        buf.append('=");
        buf.append(value);
    
public voidonReceiveIntent(android.content.Context context, android.content.Intent intent)


          
        if (intent.getAction().equals(ACTION)) {
            StringBuilder buf = new StringBuilder();
            buf.append("Got data message, action=");
            buf.append(ACTION);

            Bundle bundle = intent.getExtras();
            if (bundle != null) {

                if (bundle.getString("poke") != null) {
                    appendData(buf, "poke", bundle.getString("poke"));
                }

                if (bundle.getString("question") != null) {
                    appendData(buf, "question", bundle.getString("question"));
                }
            }

            Log.i(LOG_TAG, "[XmppDataMessageReceiver] onReceiveIntent: " + buf);


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

            nm.notifyWithText(123, buf.toString(),
                    NotificationManager.LENGTH_LONG, null);

        }