Register 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();
}
}
Next topic: Create a subclass of BBMPlatformApplication