Contoh kode: Mengirim pesan ke kontak
Contoh kode berikut mengasumsikan bahwa kelas yang menampilkan MyBBMScreen telah memberikan referensi untuk objek BBMPlatformContext yang terkait dengan aplikasi ini ke konstruktor MyBBMScreen.
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)
{
}
};
}
Topik berikutnya: Mengirim file ke kontak
Topik sebelumnya: Mengirim pesan ke kontak
Apakah informasi ini berguna? Kirimkan komentar Anda kepada kami.