Share content with a user's BBM contacts

The net.rim.blackberry.api.bbm.platform.service.MessagingService class provides a method that allows your application to share content with a user's BlackBerry Messenger contacts.

To share content, invoke shareContent() on the MessagingService object that is associated with your application and pass in the content that you want to share (for example, a URL), a cookie that is associated with the content, and a title that is displayed in the contact picker UI. By default, shareContent() displays the contact picker with all of the user's BBM contacts. You can use the ignoreList argument to provide a list of contacts that the user can choose to ignore.

// Retrieve the messaging service associated with your application
MessagingService msgService = _platformContext.getMessagingService();

String content = "<content to share>";
String cookie = "<cookie>";

// Provide a list of contacts that the user can choose to ignore
// or pass in null

BBMPlatformContactList igonoreList = new BBMPlatformContactList();
ignoreList.add(pickContact());

msgService.shareContent(content, new BBMPlatformData(cookie), 
                         "Contact Picker Title", ignoreList);


// Create a list of contacts that have your app installed

public BBMPlatformContact pickContact()
{
    UIService uiService = _platformContext.getUIService();
    BBMPlatformContactList bbmPlatformContactList = uiService.showContactPicker(
      "All Contacts", ContactListProvider.BBM_CONTACTS_WITH_APP, false, false);
    BBMPlatformContact platformContact = null;

    if (bbmPlatformContactList != null)
    {
        try
        {
           platformContact = (BBMPlatformContact) 
            bbmPlatformContactList.getAll().nextElement();
        } 
        catch(NoSuchElementException e) 
        {
           // Code that runs if no more elements exist     
        } 
        finally
        {
           return platformContact;    
        }
    } 
    else
    {
        return null;
    }
}

Was this information helpful? Send us your comments.