Start a BlackBerry Messenger chat

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 MyBBMChatScreen 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 application's associated BBMPlatformContext.
    public class MyBBMChatScreen extends MainScreen
    {
        public MyBBMChatScreen(BBMPlatformContext platformContext) 
        {
    
        }
    }
  3. Invoke BBMPlatformContext.getUIService().startBBMChat() to open a chat window. You must specify a message as a parameter. This message appears in the reply field of the conversation window. You can specify a contact to chat with by passing in a parameter. If you do not specify a contact, a contact picker UI component containing all the contacts in the user's BlackBerry Messenger contact list will open automatically.
    public class MyBBMChatScreen extends MainScreen
    {
        public MyBBMChatScreen(BBMPlatformContext platformContext) 
        {
            platformContext.getUIService().startBBMChat("Let's chat");
        }
    }

Code sample: Starting a BBM Chat

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 MyBBMChatScreen extends MainScreen
{
    public MyBBMChatScreen(BBMPlatformContext platformContext)
    {
        platformContext.getUIService().startBBMChat("Let's chat!");
    }
}
Back To Top
Previous topic: Interacting with contacts

Was this information helpful? Send us your comments.