Send a session invitation to a contact
Before you begin: Make sure that you
have completed the task,
Register your
application with the BlackBerry Messenger platform, and that the class
that displays the screen passes in a reference to the application's associated
BBMPlatformContext object into the screen's contructor.
-
Import the required classes and interfaces.
import net.rim.blackberry.api.bbm.platform.*;
import net.rim.blackberry.api.bbm.platform.service.*;
import net.rim.device.api.ui.component.*;
-
Define a session listener. The code
sample in step 5 assumes that you named the listener class,
MySessionListener.
-
Create a class that extends
MainScreen. In the constructor for this screen
class, pass in the application's associated
BBMPlatformContext object.
public class MyBBMInviteScreen extends MainScreen
{
public MyBBMInviteScreen(BBMPlatformContext platformContext)
{
}
}
-
In the constructor, retrieve a reference to the messaging service
associated with this application's platform context.
public class MyBBMInviteScreen extends MainScreen
{
public MyBBMInviteScreen(BBMPlatformContext platformContext)
{
MessagingService messagingService = platformContext.getMessagingService();
}
}
-
Invoke
MessagingService.createSession() to create a new
BBMPlatformSession instance. Pass in an instance of
the listener, that you defined in step 2, as a parameter.
public class MyBBMInviteScreen extends MainScreen
{
public MyBBMInviteScreen(BBMPlatformContext platformContext)
{
MessagingService messagingService = platformContext.getMessagingService();
BBMPlatformSession mySession = messagingService.createSession(new MySessionListener());
}
}
-
Invoke
BBMPlatformSession.sendInvitation() to invite a
contact to your session. The
sendInvitation()method can take three parameters.
The first parameter specifies a message to be delivered when the contact
receives the invitation. The second parameter is an argument that will be
passed to the application's main method as
args[1]. The third parameteris the invitation's
expiry time. The following code sample passes in the value 0 for expiry time
(that is, the invitation never expires). A Contact picker UI component will
automatically open for the user to choose a contact to invite.
public class MyBBMInviteScreen extends MainScreen
{
public MyBBMInviteScreen(BBMPlatformContext platformContext)
{
MessagingService messagingService = platformContext.getMessagingService();
BBMPlatforSession mySession = messagingService.createSession(new MySessionListener());
if (mySession != null)
{
mySession.sendInvitation(“Let's play a game”, "Poker App", 0);
}
}
}
Code sample: Sending a session join invitation to a contact
The following code sample assumes that the class that displayed the
MyBBMInviteScreen has passed a reference to the
application's associated
BBMPlatformContext object into the
MyBBMScreen constructor.
This code sample also assumes that you have completed the task,
Define a session listener
and named the session listener class,
MySessionListener.
import net.rim.blackberry.api.bbm.platform.*;
import net.rim.blackberry.api.bbm.platform.service.*;
import net.rim.device.api.ui.component.*;
public class MyBBMSessionScreen extends MainScreen
{
public MyBBMSessionScreen(BBMPlatformContext platformContext)
{
MessagingService messagingService = platformContext.getMessagingService();
BBMPlatforSession mySession = messagingService.createSession(new MySessionListener());
if (mySession != null)
{
mySession.sendInvitation(“Let's play a game”, "Poker App", 0);
}
}
}
Was this information helpful? Send us your comments.