Create an information provider for a linked contact

You can create a class that extends the abstract LinkedContactInfoProvider class to define information about a linked contact. This information appears in the Contacts application on the BlackBerry® device when a user views a contact that is linked with a contact in your application.
  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.pdap.contactlinking.*;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    
  2. Create a class that extends LinkedContactInfoProvider.
    public class SampleLinkedContactInfoProvider extends LinkedContactInfoProvider
    {
        private Image _image;
        private String _appName;
            
        public SampleLinkedContactInfoProvider(Image image, String appName)    
        {        
            _image = image;
            _appName = appName;                
        }
    
  3. Implement getAppImage() and return the icon that represents your application. The method must return an image in order for any information to appear for your linked contact when a user views a contact in the Contacts application.
    public Image getAppImage()
    {
        return _image;        
    }
    
  4. Implement getAppName() and return the name of your application. The method must return a name in order for information about the linked contact to appear when a user edits a contact in the Contacts application.
    public String getAppName()
    {        
        return _appName;
    }  
    
  5. To indicate which LinkedContactInfoProvider fields (user name, availability, or status) that your application supports, implement isSupported(). By default, a field is not supported. You need to implement isSupported() only if your application supports any of the fields.
    public boolean isSupported(int capability)
    {
        switch(capability)
        {
            case LinkedContactInfoProvider.STATUS:
            case LinkedContactInfoProvider.AVAILABILITY:
            case LinkedContactInfoProvider.USER_NAME:
                return true;
            default:
                return false;
        }
    }
    
  6. Implement requestFields() to specify the information to display for the contact in the Contacts application. The method is invoked by the framework when it needs to display information for the linked contact in the Contacts application. Specify the contact's name, status, and current availability, depending on which fields you defined as supported in isSupported().
    public void requestFields(String contactID, final LinkedContactCallback callback, int fields)
    {        
        LinkableContact contact = ContactListScreen.getUserForID(contactID);
            
        if((fields & LinkedContactInfoProvider.AVAILABILITY) != 0)
        {
            callback.setAvailability(LinkedContactInfoProvider.AVAILABILITY_ONLINE);
        }
        if((fields & LinkedContactInfoProvider.STATUS) != 0)
        {            
            callback.setStatusString("<Sample contact status>");
        }       
        if((fields & LinkedContactInfoProvider.USER_NAME) != 0)
        {
            callback.setUserName(contact.toString());
        }
    }    
    
  7. Register the information provider with your application.
    LinkedContactUtilities.registerLinkedContactInfoProvider(
        new SampleLinkedContactInfoProvider(imageBlue, "Demo App 1"), 
        APPLICATION_ID,
        LinkedContactConstants.COMPOSE_SN_MENU_GROUP);
    
    This example registers the application as a social networking application, using the COMPOSE_SN_MENU_GROUP field in LinkedContactConstants.
When a user displays a contact in the Contacts application that is linked to one of your contacts, the information that you defined in your information provider displays on the contact screen. The framework determines the layout of the information. In this example, because the application was defined as a social networking application, the information displays in the Social Networks section of the contact.

Code sample: Creating an information provider for a linked contact

To see an example of creating an information provider for a linked contact, see the SampleLinkedContactInfoProvider class in the Contact Linking Demo sample application that is included in the BlackBerry® Java® SDK.

Next topic: Task list

Was this information helpful? Send us your comments.