Sono nuovo all'uso della libreria smack e faccio una chat. Ho fatto molta parte e in questa fase voglio fare due domande.Android AGGIUNGI IL TUO AMICO usando Smack
quando aggiungo un amico l'amico ha ottenuto aggiunto nella mia lista, ma non c'è alcuna notifica inviata alla amico che ho aggiunto, Come raggiungere lo stesso. Ho aggiunto il codice qui sotto.
La seconda cosa che voglio chiedere è che come posso verificare se l'utente che sto per aggiungere è una parte o membro dell'app o no (significa che è sul server o no). In modo che l'utente che non è registrato per l'app non dovrebbe essere aggiunto nell'elenco degli amici.
Ecco il codice
public static boolean addFriend(String jid) {
String nickname = null;
nickname = StringUtils.parseBareAddress(jid);
RosterEntry entry4 = roster.getEntry("samsad");
if (!roster.contains(jid)) {
try {
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo(jid);
connection.sendPacket(subscribe);
roster.createEntry(jid, nickname, null);
// Send a roster entry (any) to user2
RosterExchangeManager REM = new RosterExchangeManager(connection);
REM.send(entry4, jid);
return true;
} catch (XMPPException e) {
System.err.println("Error in adding friend");
return false;
}
} else {
return false;
}
}
direttore Roster cambio in esecuzione nel servizio in background
/**Remotr Exchange Manager*/
RosterExchangeManager rem = new RosterExchangeManager(connection);
// Create a RosterExchangeListener that will iterate over the received roster entries
RosterExchangeListener rosterExchangeListener = new RosterExchangeListener() {
public void entriesReceived(String from, Iterator remoteRosterEntries) {
notification("Receive==4");
while (remoteRosterEntries.hasNext()) {
try {
// Get the received entry
RemoteRosterEntry remoteRosterEntry = (RemoteRosterEntry) remoteRosterEntries.next();
// Display the remote entry on the console
System.out.println(remoteRosterEntry);
// Add the entry to the user2's roster
roster.createEntry(
remoteRosterEntry.getUser(),
remoteRosterEntry.getName(),
remoteRosterEntry.getGroupArrayNames());
notification("Receive==1");
}
catch (XMPPException e) {
e.printStackTrace();
}
}
}
};
rem.addRosterListener(rosterExchangeListener);
}
else{
showToast("Connection lost-",0);
}
}
@Trickster si prega di rispondere ora –