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 onContactLeft(BBMPlatformContact contact)
{
String goodbyeMsg = contact.getDisplayName() + " has left the game.";
BBMPlatformData data = new BBMPlatformData(goodbyeMsg);
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 contactsJoined(BBMPlatformConnection conn, BBMPlatformContactList contacts, String cookie,
int type)
{
}
public void contactDeclined(BBMPlatformConnection conn, BBMPlatformContact contact)
{
}
public void contactLeft(BBMPlatformConnection conn, BBMPlatformContact contact)
{
onContactLeft(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