BlackBerry Messenger 플랫폼에 프로그램 등록
시작하기 전에: BBMPlatformApplication의 하위 클래스 만들기.
- 필요한 클래스와 인터페이스를 가져옵니다.
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;
- UiApplication 클래스를 확장하여 프로그램 구조를 만듭니다. 새 클래스에서 MyBBMAppPlugin 인스턴스를 MyBBMPlatformApp 클래스의 멤버 변수로 선언합니다.
public class MyBBMPlatformApp extends UiApplication
{
private MyBBMAppPlugin myPlugin;
}
- MainScreen 클래스를 확장하여 사용자 정의 화면의 구조를 만듭니다.
private class MyBBMPlatformScreen extends MainScreen
{
MyBBMPlatformScreen()
{
setTitle("My BBM Platform screen");
}
}
- MyBBMPlatformApp 클래스 생성자에서 MyBBMAppPlugin 클래스 인스턴스를 만들고 pushScreen()을 호출하여 프로그램 화면을 표시합니다.
public MyBBMPlatformApp()
{
myPlugin = new MyBBMAppPlugin();
pushScreen(new MyBBMPlatformScreen());
}
- 동일한 생성자에서 invokeLater(new Runnable())을 호출, 프로그램의 이벤트 큐에 개체를 추가합니다. 프로젝트에서 run() 메소드는 try/catch 블록에서 BBMPlatformManager.register()를 호출하여 플러그인을 BlackBerry®
Messenger 플랫폼에 등록합니다. register() 메서드는 이 프로그램에 대한 BBMPlatformContext 개체를 반환합니다.
invokeLater(new Runnable()
{
public void run(
{
BBMPlatformContext platformContext = null;
try
{
platformContext = BBMPlatformManager.register(myPlugin);
}
catch (ControlledAccessException e)
{
// BBM Social Platform has been disabled
}
- 컨텍스트 변경 수신기 정의. 7단계의 코드 샘플에서는 컨텍스트 변경 수신기 하위 클래스 이름이 MyBBMPlatformContextChangeListener로 지정되었고 BBMPlatformContextListener 인터페이스를 구현하는 것으로 가정합니다.
- run() 메서드에서 BBMPlatformContextListener의 새 인스턴스를 만들고 BBMPlatformContext.setChangeListener()를 호출하여 BBMPlatformContext에 수신기를 할당합니다.
if (platformContext != null)
{
MyBBMPlatformContextListener platformContextListener;
platformContextListener = new MyBBMPlatformContextListener();
platformContext.setListener(platformContextListener);
}
}
}
);
- MyBBMPlatformApp 클래스에서 main() 메서드를 생성합니다. main()에서 MyBBMPluginApp 클래스의 인스턴스를 만들고 프로그램을 시작할 단말기의 이벤트 스레드에 추가하여 이벤트를 수신하도록 합니다.
public static void main(String[] args)
{
MyBBMPlatformApp theApp = new MyBBMPlatformApp();
theApp.enterEventDispatcher();
}
이제
BlackBerry Messenger 플랫폼에 프로그램이 등록되었습니다.
코드 샘플: BlackBerry Messenger 플랫폼에 프로그램 등록
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();
}
}
이 정보가 도움이 되었습니까? 의견을 보내 주십시오.