Create a custom field for linked contacts
You can create a custom field that appears in the contacts application on the
BlackBerry® device when a user selects a contact that is linked with a contact in your application.
- 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.*;
- Create a class that implements the AddressBookFieldFactory interface.
public final class SampleAddressBookFieldFactory implements AddressBookFieldFactory
{
private String _applicationName;
public SampleAddressBookFieldFactory(String appName)
{
_applicationName = appName;
}
}
- In the class you created in the previous step, implement AddressBookFieldFactory.createAddressBookField(), which defines the field that you want to add to the contacts application.
public Field createAddressBookField(final String contactID)
{
LinkableContact user = ContactListScreen.getUserForID(contactID);
if(user == null)
{
return null;
}
return new BasicEditField(_applicationName + ": ",
user.getString(LinkableContact.NAME),
BasicEditField.DEFAULT_MAXCHARS,
Field.USE_ALL_WIDTH | Field.READONLY);
}
- Create a variable to store the unique ID of your application.
public static final long APPLICATION_ID = 0x819417e94b6ca3b7L;
- Instantiate the AddressBookFieldFactory and register it with your application.
AddressBookFieldFactory factory = new SampleAddressBookFieldFactory("Sample App");
LinkedContactUtilities.registerAddressBookFieldFactory(factory, APPLICATION_ID);
When a user selects a contact
in the contacts application that is linked with a contact in your application, the field that you defined in step 3 appears on the screen of the
BlackBerry device.
Code sample: Creating a custom field for linked contacts
To see an example of creating a custom field, see the SampleAddressBookFieldFactory class and the ContactLinkingDemo class in the sample application for contact linking. To download the sample application, visit
www.blackberry.com/go/contactlinkingsample.
Was this information helpful? Send us your comments.