Create a Send menu

In this task, an edit field is created that accepts text that a BlackBerry device user types. This text is stored in a context object, and this context object is used to retrieve a list of Send menu commands whose associated applications can accept the text. A Send menu is created with these Send menu commands.

To specify the appearance of the EditField object, invoke setBorder(), setPadding(), and setMargin(). In this task, a bevel border is created for the EditField object, and a padding area and margin area are added.

Invoke super.makeMenu() to add the default menu items for BlackBerry device applications to the menu.

super.makeMenu(menu, instance);

Invoke getText() of the EditField class to retrieve the text that the user typed in the edit field.

_textString = _textToSend.getText();

Create a new JSONObject object to represent the context information for the Send menu.

JSONObject context = new JSONObject();

In a try/catch block, invoke put() of the JSONObject object to populate the context information using key-value pairs. Use the constants that are defined in the SendCommandContextKeys class as keys. Catch a JSONException, which indicates that the specified key is null.

Create an array of SendCommand objects to represent the Send menu commands that you want to include in the Send menu. Invoke SendCommandRepository.getInstance() to retrieve the singleton instance of the SendCommandRepository. Invoke get() and specify as parameters the type of content to send, the context information for the content, and a boolean value that indicates whether all of the commands should be retrieved regardless of whether their associated applications can be opened.