11-27-2011 03:18 PM
Is it still possible to create a BBM received listener in an application with the BlackBerry Social Platform SDK ?
The Social Platform looks more like a tool developers would use to create their own sessions then they would be able to listen to events within those created sessions. What I believe is the new Social Platform is meant to replace http://www.blackberry.com/developers/docs/7.0.0api
Here is what I think would've been a working BBM received listener back in the old API.
//Get BlackBerryMessenger instance
BlackBerryMessenger bm = BlackBerryMessenger.getInstance();
bm.addSessionRequestListener(new BlackBerrySessionRequestListener(), ApplicationDescriptor.currentApplicationDescriptor
class BlackBerrySessionRequestListener implements SessionRequestListener
{
public void sessionRequestAccepted(Session session)
{
session.addListener(new BlackBerrySessionListener(), ApplicationDescriptor.currentApplicationDescriptor
}
}
class BlackBerrySessionListener implements SessionListener
{
public void messageReceived(Session session, Message message)
{
//Message is Received!
//Get UID of the contact that messaged us!
session.getContact().getContactId();
}
//These are not part of my point.
public void sessionClosed(Session session) {}
public void messageDelivered(Session session, Message message) {}
public void messageQueuedForSend(Session session, Message message) {}
public void messageSent(Session session, Message message) {}
}
See I want to be able to tell if a message has been received on BlackBerry Messenger, then I want to be able to grab the P.I.N or maybe other unique identifer info from that message received event.
I do not think the functionality is available on the new BBM SDK and the old one I just linked to of course does not work anymore. Does anyone have any ideas?
11-28-2011 02:16 AM
Use this listner:
private final BBMPlatformChannelListener _channelListener = new BBMPlatformChannelListener()
{
public void contactsInvited(BBMPlatformConnection connection, BBMPlatformContactList contactList)
{
//contactsInvited
}
public void contactsJoined(BBMPlatformConnection connection, BBMPlatformContactList contactList, final String cookie, int type)
{
BBMPlatformContact contact = (BBMPlatformContact) contactList.getAll().nextElement();
if (type == CONTACT_INVITING_ME)
{
}
else if (type == CONTACT_INVITED_BY_ME)
{
}
}
public void contactDeclined(BBMPlatformConnection connection, BBMPlatformContact contact)
{
//contactDeclined
}
public void contactLeft(BBMPlatformConnection connection, BBMPlatformContact contact)
{
_callback.onContactLeft(contact);
}
// someone sent me some data in the channel
public void dataReceived(BBMPlatformConnection connection, BBMPlatformContact sender, BBMPlatformData data)
{
String msg = data.getDataAsString();
String type = data.getContentType();
onMessageReceived(sender, type, msg);//here you call the your own method;
}
public void joinRequestReceived(BBMPlatformConnection connection, BBMPlatformIncomingJoinRequest request, String param)
{
request.accept(null); // automatically accept all public requests
}
public void joinRequestCanceled(BBMPlatformConnection connection, BBMPlatformIncomingJoinRequest request, int code)
{
//joinRequestCanceled
}
};create your own function of onMessageReceived();
11-28-2011 07:26 AM
Is there a function I have to use to add that listener? I don't think it'll just work by itself will it ?
11-28-2011 06:07 PM
Up
11-28-2011 11:17 PM
See first the sample demos provided by BBM Sdk 1.1 or BBM SDK 1.2(Latest) TicTacToe Application. You can understand very well.
When you create your own application, at starting time:
BBMPlatformApplication bbmPlatformApplication=new BBMPlatformApplication(UUID); BBMPlatformContext bbmPlatformContext=BBMPlatformManager.register(bbmPlatformApplication); bbmPlatformContext.setListener(bbmPlatformContextL istener);
bbmPlatformContextListener is the listener which I provided above. This listner works up to the applicaiton close. whenever any message comes this will invoke.
11-28-2011 11:24 PM
That won't work with the listener you provided above.
The listener you provided above is a BBMPlatformChannelListener, bbmPlatformContext.setListener requires a BBMPlatformContextListener as the arguement.
11-30-2011 07:44 AM
up
11-30-2011 08:28 PM - edited 11-30-2011 08:29 PM
Sorry only looked very briefly, perhaps misunderstood the questions.
AFAIK, in your program you can't get access to standard BBM chat or in fact any communication that is being directed to any other application but your own. In addition your application can not get hooked in to another application's session or channels.
What are you actually trying to do?
11-30-2011 09:38 PM
@peter_strange Well you see I'm making this app that can make LED flash different colours when you get messages from different people. So I got text messages working fine, users can enter a number and select what colour they want the LED to flash. However, I can't do the same with BBM because I can't listen to BBM messages like I can listen to text messages.
12-01-2011 04:09 AM
I see - nice idea.
Sorry I am not aware of a way of doing this with BBM.