Join a public BlackBerry Messenger session

Before you begin: Make sure that you have registered your application with the BlackBerry Messenger platform, and that the class that displays the MyBBMSessionScreen screen passes in a reference to the application's associated BBMPlatformContext object into the screen's contructor.
  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.bbm.platform.*;
    import net.rim.blackberry.api.bbm.platform.service.*;
  2. Create a class that extends MainScreen. In the constructor for this screen class, pass in the BBMPlatformContext object that is associated with your application.
    public class MyBBMSessioncreen extends MainScreen
    {
        public MyBBMSessionScreen(BBMPlatformContext platformContext) 
        {
    
        }
    }
  3. In the constructor, retrieve a reference to the messaging service for the application.
    public class MyBBMSessionScreen extends MainScreen
    {
        public MyBBMSessionScreen(BBMPlatformContext platformContext) 
        {
            MessagingService messagingService = platformContext.getMessagingService();
        }
    }
  4. Invoke MessagingService.sendJoinRequest() to send a join request to a public session with the specified host ID, host PPID, and another parameter that you want to send to the host (for example, you could tell the host what level you would like to start on if the event is a game). The host must provide you with the host ID, host PPID, and a string that provides some additional information (this can be achieved using a matchmaking server that you must set up). The sendJoinRequest() method returns a BBMPlatformOutgoingJoinRequest object. A confirmation dialog is displayed when you invoke this method. If you want to cancel the join request before it is accepted or declined by the host, invoke BBMPlatformOutgoingJoinRequest.cancel().
    public class MyBBMSessionScreen extends MainScreen
    {
        public MyBBMSessionScreen(BBMPlatformContext platformContext) 
        {
            BBMPlatformOutgoingJoinRequest request = 
             messagingService.sendJoinRequest(123456, "12344567", "My game");
            if (request.getStatus() == BBMPlatformJoinRequest.REQUEST_STATUS_ACCEPTED)
             {
                 Dialog.inform("Welcome to My Chess Game");
             }
             else
             {
                 Dialog.inform("The request was declined");
             }
    	   }
    }

Code sample: Joining a public session

The following code sample assumes that the class that displayed the MyBBMChatScreen has passed a reference to the application's associated BBMPlatformContext object into the MyBBMChatScreen constructor.

import net.rim.blackberry.api.bbm.platform.*;
import net.rim.blackberry.api.bbm.platform.service.*;

public class MyBBMInviteScreen extends MainScreen
{
    public MyBBMInviteScreen(BBMPlatformContext platformContext) 
    {
        BBMPlatformOutgoingJoinRequest request = 
             messagingService.sendJoinRequest(123456, "12344567", "My game");
           if (request.getStatus() == BBMPlatformJoinRequest.REQUEST_STATUS_ACCEPTED)
           {
              Dialog.inform("Welcome to My Chess Game");
            }
            else
            {
              Dialog.inform("The request was declined");
            }
	   
    }
}
Back To Top

Was this information helpful? Send us your comments.