Java Reference
In-Depth Information
The same login, event-handling and session-establishing operations
performed here are used in all other examples.
B.5.4 Presence
Now that we know how to do the basics, let us look at how to use
the Presence feature on our connected games. It allows us to notify our
friends whether we are available, busy, away, and so on. And, of course,
it's possible also to receive events about the presence status of our friends.
In order to test this application, we start two emulator instances. In the
first one, we run the Presence example configured with only a username
and password. These are used to log in to the server and wait for an
event to happen. In the second emulator, we run the Presence example
configured with the name of a friend of the first user. Upon checking that
a friend name exists in the JAD file, the application sends a friend request
to the first application instance, which accepts it automatically:
import com.nokia.sm.client.* ;
import com.nokia.sm.params.*;
public class Presence extends MIDlet implements CommandListener {
private int gameClassID = 17513;
private String friendname;
...
public void startApp() {
/* Setup code omitted for brevity */
String username = getAppProperty("username");
String password = getAppProperty("password");
friendname = getAppProperty("friendname");
...
if(friendname!= null && friendname.trim().length() == 0)
{
friendname = null;
} // set eventListener
SMClient smClient = null;
try {
smClient = new SMClient(new EventListener());
console.println("Sending login info:" + username + ":" + password,
Console.GREEN);
smClient.loginSingleSignon(username, password, null, null,
gameClassID, null, 0, null, 0, false, null);
} catch(Exception e) {
e.printStackTrace();
}
} public void destroyApp(boolean unc)
{
smSession.logout();
} public void setPresenceStatus(final Friend friend) {
smSession.setPresence(Friend.PRESENCE_STATUS_BUSY, "I'M AWAY");
console.println("My Presence changed to AWAY", Console.YELLOW);
}
 
Search WWH ::




Custom Search