BlackBerry Dynamics (BD) apps can communicate with each other using the Shared Services Framework, a collaboration system that is defined by two components: one that provides a service and another that consumes the service.
You can use this to communicate between two of your own BD apps; however it’s more common to use the capability to integrate with other BD apps. For example, you could use shared services to pass a PDF to a printing application, or to create a draft email message. Both BlackBerry and our development community have defined services for common tasks. This means all BD apps can perform common actions – such as sharing a file or opening a URL – using the same service. Services can be scoped to be public and available for any application to use, or they can be private and internal to an organization. All public Shared Services are listed on the BlackBerry Marketplace Service Listing. Each service also shows the applications that are providers of it.
Your application could implement either side of the service. It could be the consumer and send data to another application or it could be the provider and receive data from another application. Today we’re going to look at how to consume a service. Let’s use the Send Email Service to create an email.
The sample code shown in this article was taken from our Android SharedServicesTestApp and iOS BEMS-SharedServices samples. You can clone and run these sample to follow along. The Android sample demonstrates how to consume the following services:
The iOS sample demonstrates how to consume the following services:
Step 1 – Finding a Service Provider
The first step is to determine which applications are installed on the device that are providers for the service we want to use, in this case the Send Email Service. In order to query a service, we need to know its service ID and version. Both of those can be found in the service’s listing on the BlackBerry Marketplace. For the Send Email Service, those are:
Service ID: com.good.gfeservice.send-email
Service Version: 18.104.22.168
With this information, we can query to determine what – if any – applications active on this device provide this service. If no providers are found, we can warn the user or disable this feature in our app. Query for service providers like this: