Send a join 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 in the following code sample passes in a reference to
the application's associated
BBMPlatformContext object.
-
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.*;
-
Create a class that extends
MainScreen. In the constructor for this screen
class, pass in the application's associated
BBMPlatformContext.
public class MyBBMInviteScreen extends MainScreen
{
public MyBBMInviteScreen(BBMPlatformContext platformContext)
{
}
}
-
In the
MyBBMInviteScreen 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();
}
}
-
Define a channel listener.
The code sample in step 5 assumes that you named the listener class,
MyChannelListener.
-
Invoke
MessagingService.createChannel() to create a new
BBMPlatformChannel, passing in your channel listener
class.
public class MyBBMInviteScreen extends MainScreen
{
public MyBBMInviteScreen(BBMPlatformContext platformContext)
{
MessagingService messagingService = platformContext.getMessagingService();
BBMPlatformChannel channel = messagingService.createChannel(new MyChannelListener());
}
}
-
In an
if statement that checks whether you created the
BBMPlatformChannel successfully, invoke
BBMPlatformChannel.sendInvitation() to invite a
contact to your application. In the parameters for
sendInvitation(), you can specify a message to be
displayed when the contact receives the invitation, a parameter that will be
passed to the application's main method as
args[1], and an 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 opens for the user to choose a contact
to invite.
public class MyBBMInviteScreen extends MainScreen
{
public MyBBMInviteScreen(BBMPlatformContext platformContext)
{
MessagingService messagingService = platformContext.getMessagingService();
BBMPlatformChannel channel = messagingService.createChannel(new MyChannelListener());
if (channel != null)
{
channel.sendInvitation(“Let's play a game”, "Chess App", 0);
}
}
}
After you finish:
You can interact with the contact that you invited to your channel
when they accept your invitation.
Code sample: Sending a 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 channel listener
and named the channel listener class,
MyChannelListener.
import net.rim.blackberry.api.bbm.platform.*;
import net.rim.blackberry.api.bbm.platform.service.*;
import net.rim.device.api.ui.component.*;
public class MyBBMInviteScreen extends MainScreen
{
public MyBBMInviteScreen(BBMPlatformContext platformContext)
{
MessagingService messagingService = platformContext.getMessagingService();
BBMPlatformChannel channel = messagingService.createChannel(new MyChannelListener());
if (channel != null)
{
channel.sendInvitation(“Let's play a game”, "Chess App", 0);
}
}
}
Was this information helpful? Send us your comments.