Codevoorbeeld: een bericht verzenden naar een contactpersoon
In het volgende codevoorbeeld wordt aangenomen dat de klasse die MyBBMScreen heeft weergegeven, een verwijzing naar het bijbehorende BBMPlatformContext-object van de toepassing in de constructor MyBBMScreen heeft doorgegeven.
import net.rim.blackberry.api.bbm.platform.*;
import net.rim.blackberry.api.bbm.platform.io.*;
import net.rim.blackberry.api.bbm.platform.profile.*;
import net.rim.blackberry.api.bbm.platform.service.*;
import net.rim.device.api.ui.component.*;
public class MyBBMScreen extends MainScreen
{
public MyBBMScreen(BBMPlatformContext platformContext)
{
MessagingService messagingService = platformContext.getMessagingService();
_channel = messagingService.createChannel(_channelListener);
_channel.sendInvitation("Let's play a game", "Chess App", 0);
}
private void onContactJoined(BBMPlatformContact contact)
{
String welcomeMsg = "Please welcome " + contact.getDisplayName() + " to the game.";
BBMPlatformData data = new BBMPlatformData(welcomeMsg);
try {
_channel.sendData(data, _channel.getContactList());
}
catch (BBMPlatformException e)
{
//error handler code
}
}
private BBMPlatformChannelListener _channelListener = new BBMPlatformChannelListener()
{
public void contactsInvited(BBMPlatformConnection conn, BBMPlatformContactList contactList )
{
}
public void contactJoined(BBMPlatformConnection conn, BBMPlatformContact contact, String cookie)
{
onContactJoined(contact);
}
public void contactDeclined(BBMPlatformConnection conn, BBMPlatformContact contact)
{
}
public void contactLeft(BBMPlatformConnection conn, BBMPlatformContact contact)
{
}
public void dataReceived(BBMPlatformConnection conn, BBMPlatformContact sender, BBMPlatformData data)
{
}
};
}
Volgend onderwerp: Een bestand verzenden naar een contactpersoon
Vorig onderwerp: Een bericht verzenden naar een contactpersoon