Retrieving Send commands

To create a Send menu in your application, you must retrieve a set of commands to include in the menu. Each command corresponds to an application that BlackBerry device users can use to send content from your application. For example, you can retrieve commands that correspond to sending an email message, an SMS text message, and so on.

You can use the SendCommandRepository class to retrieve commands to use in a Send menu. The SendCommandRepository class contains all of the commands that are registered on the device, and you can include these commands in the Send menu. The SendCommandRepository class is a singleton class, and you can retrieve the singleton instance of this class by invoking the static SendCommandRepository.getInstance(). You can then retrieve an array of commands by invoking get(). Commands are represented by SendCommand objects, and so invoking get() returns an array of SendCommand objects.

When you invoke get() to retrieve commands, you must provide a set of parameters that defines the types of commands that you want this method to return. The following table describes the parameters that you must provide and how each parameter affects the types of commands that you receive.

Parameter

Description

type

This parameter is an int value that represents the type of content that your application allows users to send using the Send menu. You can specify two values for this parameter, both of which are constants that are included in SendCommand:

  • SendCommand.TYPE_TEXT: This constant indicates that your application allows users to send text, and that the context parameter contains information that is related to the text to send.
  • SendCommand.TYPE_PATH: This constant indicates that your application allows users to send files, and that the context parameter contains information that is related to the file to send.

context

This parameter is a JSONObject object that represents the content to send. This object contains a set of key-value pairs that determine what content is sent and what fields are populated in the application that sends the content. For example, the JSONObject object might contain the path of the file to send, or the subject and body of a message to create. You can use the constants that are included in the SendCommandContextKeys class as keys for the content.

availability

This parameter is a boolean value that indicates whether get() returns all commands regardless of whether their associated applications can be opened.

This parameter is optional.

The get() method returns SendCommand objects that support both the type and the context that you specify. For example, if you specify a type of SendCommand.TYPE_PATH, the array of SendCommand objects that you receive from get() will not include a command that is associated with sending an SMS text message because files cannot be sent using SMS text messages.

You can use the following code snippet to retrieve a set of commands from a SendCommandRepository. These commands are associated with applications that support sending text content to a recipient, such as the Messages application, and do not include commands that are associated with applications that cannot be opened.

SendCommand[] sendCommands = SendCommandRepository.getInstance().get(SendCommand.TYPE_TEXT, context, false);
Previous topic: Send Menu API

Was this information helpful? Send us your comments.