venerdì 30 ottobre 2009

Google XMPP gTalk Notifier

Example :
package com.vincenzoamoruso.notifier;

import java.util.logging.Logger;

import com.google.appengine.api.xmpp.JID;
import com.google.appengine.api.xmpp.Message;
import com.google.appengine.api.xmpp.MessageBuilder;
import com.google.appengine.api.xmpp.SendResponse;
import com.google.appengine.api.xmpp.XMPPService;
import com.google.appengine.api.xmpp.XMPPServiceFactory;


public class XMPPNotifier {
private static final Logger log = Logger.getLogger(XMPPNotifier.class.getName());

public boolean sendXMPP(String toID,String Message,boolean tryByMail){
JID jid = new JID(toID);
String msgBody = Message;
Message msg = new MessageBuilder()
.withRecipientJids(jid)
.withBody(msgBody)
.build();
boolean messageSent = false;
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
if (xmpp.getPresence(jid).isAvailable()) {
SendResponse status = xmpp.sendMessage(msg);
messageSent = (status.getStatusMap().get(jid) == SendResponse.Status.SUCCESS);
}
if (!messageSent) {
System.out.println("Non Inviato");
log.warning("Non Inviato");
}
return messageSent;
}
}

in riferimento a: g - Cerca con Google (visualizza su Google Sidewiki)

Nessun commento:

Posta un commento