Java Reference
In-Depth Information
Doing this triggers another event, but this time on the requestor:
public void friendRequestAccepted(Friend from) {
console.println("Friend request accepted!", Console.GREEN);
// set the presence
We are told that our request was accepted, and therefore we can
send our Presence information to our new friend. In subsequent logins,
this friend's information is included in the Friend[] array passed
to the application on the successful login event handler. In all cases,
whenever we receive some presence information from a friend, the
friendPresenceChanged() method is invoked; we can then use the
information passed as a parameter to make any necessary display or status
changes in our side of the application.
Testing the Presence example is a bit of work, but is not complex.
First, browse to the samples \ SampleApps \ dist folder of the SNAP
Mobile SDK installation. You will see two versions of this example:
Presence.jad and Presence2.jad . The first is configured with
username , password and friendname parameters, which means it
will log in and try to add friendname as a friend. The second is
configured with username and password only, which means it will
not invite anybody to be a friend. However, its username parameter is
configured as friendname in the first version, meaning that the friend
request sent by the first is handled by the second instance of the Presence
Open the Presence2.jad application in your emulator. The appli-
cation logs in to the SNAP Mobile server and waits for events. Open a
second instance of the emulator, executing the Presence.jad applica-
tion. It sees the friendname parameter configured and proceeds to add it
as a friend, setting the presence information and then logs out. Figure B.7
shows both applications running on the Sun WTK client emulator.
B.5.5 Instant Messaging
This final example demonstrates how to send and receive instant messages
to and from friends. The Instant Messaging and Presence examples
combined can be used as a basis for powerful games enabled with instant
messaging to run on the SNAP Mobile community server.
After logging in, one instance of the application looks for friends in the
Friend[] parameter passed by the loginSingleSignonSuccess()
callback method. If we find some, it proceeds to send messages to the
first friend in the list ( friend[0] ), using the sendMessage() method:
Search WWH ::

Custom Search