Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Registering your app with the BBM platform

Before your app can take advantage of the BlackBerry Messenger platform, you must register it with the BBM platform. When your application registers with the BBM platform, the platform returns a BBMPlatformContext object which you will need when implementing any BBM functionality in your application.

Register your app with the BBM platform

  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.bbm.platform.BBMPlatformApplication;
    import net.rim.blackberry.api.bbm.platform.BBMPlatformContext;
    import net.rim.blackberry.api.bbm.platform.BBMPlatformContextListener;
    import net.rim.blackberry.api.bbm.platform.BBMPlatformManager;
    import net.rim.device.api.ui.container.MainScreen;
    import net.rim.device.api.ui.UiApplication;
  2. Create the application framework by extending the UiApplication class. Inside the new class, declare an instance of MyBBMAppPlugin as a member variable of the MyBBMPlatformApp class.
    public class MyBBMPlatformApp extends UiApplication
    {
         private MyBBMAppPlugin myPlugin;   
    }
  3. Create the framework for a custom screen by extending the MainScreen class.
    private class MyBBMPlatformScreen extends MainScreen
    {
        MyBBMPlatformScreen()
        {
           setTitle("My BBM Platform screen");
        }
    }
  4. In the constructor for the MyBBMPlatformApp class, create an instance of your MyBBMAppPlugin class and invoke pushScreen() to display the screen for the application.
    public MyBBMPlatformApp() 
    {
        myPlugin = new MyBBMAppPlugin();
        pushScreen(new MyBBMPlatformScreen());
    }
  5. In the same constructor, call invokeLater(new Runnable()) to add the object to the event queue for your application. In the object's run() method invoke BBMPlatformManager.register() in a try/catch block to register your plug-in with the BlackBerry Messenger platform. The register() method returns a BBMPlatformContext object for this application.
    invokeLater(new Runnable()
    {
      public void run(
      {
        BBMPlatformContext platformContext = null;
            try 
            {
                platformContext = BBMPlatformManager.register(myPlugin);
            }
    	    catch (ControlledAccessException e) 
            {
                // BBM Social Platform has been disabled
            }
    
  6. /java/documentation/defining_service_listeners_1489649_11.html. The code sample in step 7 assumes that your context change listener subclass is named MyBBMPlatformContextChangeListener and that it implements the BBMPlatformContextListener interface.
  7. In the run() method, create a new instance of a BBMPlatformContextListener and invoke BBMPlatformContext.setChangeListener() to assign the listener to the BBMPlatformContext.
            if (platformContext != null) 
            {
                MyBBMPlatformContextListener platformContextListener;
                platformContextListener = new MyBBMPlatformContextListener();
                platformContext.setListener(platformContextListener);
            }
        }
     }
    );
  8. In your MyBBMPlatformApp class, create a main() method. In main() create an instance of the MyBBMPluginApp class and add it to the event thread of your device to start the application and enable it to receive events.
    public static void main(String[] args)
    {
        MyBBMPlatformApp theApp = new MyBBMPlatformApp();
        theApp.enterEventDispatcher();
    }
You have now registered your application with the BlackBerry Messenger platform.

Code sample: Registering your application with the BlackBerry Messenger platform

import net.rim.blackberry.api.bbm.platform.BBMPlatformApplication;
import net.rim.blackberry.api.bbm.platform.BBMPlatformContext;
import net.rim.blackberry.api.bbm.platform.BBMPlatformContextListener;
import net.rim.blackberry.api.bbm.platform.BBMPlatformManager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;

public class MyBBMPlatformApp extends UiApplication
{   
    private MyBBMAppPlugin myPlugin;

        public MyBBMPlatformApp()
        {
           myPlugin = new MyBBMAppPlugin();
           pushScreen(new MyBBMPlatformScreen());
           invokeLater(new Runnable()
           {
              public void run()
              {
                 BBMPlatformContext platformContext = null;
                 try 
                 {
                     platformContext = BBMPlatformManager.register(myPlugin);
                 }
                 catch (ControlledAccessException e) 
                 {
                    // The BBM platform has been disabled
                 }
                 if (platformContext != null) 
                 {
                    MyBBMPlatformContextListener platformContextListener;
                    platformContextListener = new MyBBMPlatformContextListener();
                    platformContext.setListener(platformContextListener);
                 }
              }
           }
        );
    }

    private class MyBBMPlatformScreen extends MainScreen
    {
        MyBBMPlatformScreen()
        {
            setTitle("BBM Platform application");
        }
    }

    private class MyBBMAppPlugin extends BBMPlatformApplication
    {
        public MyBBMAppPlugin()
        {
            super( "Insert your UUID here" );
        }
    }

    private class MyBBMPlatformContextListener extends BBMPlatformContextListener
    {
        public void accessChanged(boolean isAccessAllowed, int accessErrorCode)
        {
            if (!isAccessAllowed)
            {
                // You cannot access the BBM platform
            }
        }

        public void appInvoked(int reason, Object param)
        {
            // Code for handling different contexts for invocation
        }
    }

	public static void main(String[] args)
    {
        MyBBMPlatformApp theApp = new MyBBMPlatformApp();
        theApp.enterEventDispatcher();
    }
}

Create a subclass of BBMPlatformApplication

  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.bbm.platform.*;
  2. Create the application framework by extending the BBMPlatformApplication class. The BBMPlatformApplication class must be extended by any application that registers with the BlackBerry Messenger platform.
    public class MyBBMAppPlugin extends BBMPlatformApplication
    {
        
    }
  3. In the MyBBMAppPlugin class that you just created, create a constructor. If necessary, implement the methods of the superclass in the MyBBMAppPlugin class.
    public MyBBMAppPlugin()
    {
        //Add any initialization code for your application here
    }