Java Reference
In-Depth Information
/* Listener methods */
class EventListener extends SnapEventListenerAdapter {
public void loginSingleSignonSuccess(Session session,
Friend[] friends, Message[] motd) {
console.println("Login successful.", Console.GREEN);
smSession = session;
if(friends != null && friends.length != 0) {
console.println("Sending message to " + friends[0],
Console.GREEN);
setPresenceStatus(friends[0]);
} else {
if (friendname != null && friendname.trim().length() > 0) {
session.requestFriend(friendname, "Wanna Be My Friend?");
console.println("Sent friend request to " + friendname,
Console.GREEN);
}
}
} public void friendRequestReceived(User user, String message)
{
console.println("Friend request received from user" +
user.getUsername(), Console.GREEN);
// automatically accept incoming requests
smSession.acceptFriendRequest(user);
} public void friendRequestAccepted(Friend from) {
console.println("Friend request accepted!", Console.GREEN);
// set the presence
setPresenceStatus(from);
} public void friendRequestRejected(Friend friend) {
console.println("friendRequestRejected():sender = " +
friend.getUsername(), Console.YELLOW);
} public void friendPresenceChanged(Friend friend)
{
int status = friend.getPresenceStatus();
console.println(friend.getUsername() +
" changed presence status to " + status +
"-" + friend.getPresenceMessage(), Console.YELLOW);
if(status == Friend.PRESENCE_STATUS_BUSY) {
console.println("Logging out", Console.GREEN);
smSession.logout();
console.println("Presence client done!", Console.GREEN);
}
} public void errorReceived(int code, boolean mustReturnToMainMenu) {
...
}
}
// class EventListener
}
// class Presence
After setting up the console and making the JAD parameters available
to the SNAP Mobile API, we check whether the username and password
were correctly configured in the JAD file. Then we check whether the
friend name was configured or not. If it was, then the application sends an
invitation to that name, asking to be friends with it; if not, the application
 
Search WWH ::




Custom Search