Application control Sample Overview

Mobile native

The Application Control sample application uses the App Control API to search for applications supporting specific operations. The following operations have been selected in this application:

  • APP_CONTROL_OPERATION_VIEW: enables data display
  • APP_CONTROL_OPERATION_PICK: picks an item from the data
  • APP_CONTROL_OPERATION_COMPOSE: composes (for example a message)

The following figure illustrates the application view.

Figure: Application Control view

Application control view

In the main window, the application launch panel enables the user to choose one of the available operations, and search, run, and stop found applications. The message composing area enables the user to compose a message, set the destination address, and send it using the default email application.

Prerequisites

To ensure proper application execution, the following privileges must be set:

  • http://tizen.org/privilege/appmanager.kill.bgapp
  • http://tizen.org/privilege/appmanager.launch
  • http://tizen.org/privilege/email
  • http://tizen.org/privilege/datasharing

Implementation

Application Launch Panel

The controller_search_app() function is invoked on a search button click event:

void 
controller_search_app(int selected_operation_id)
{
   app_control_h app_control = NULL;

   model_free_app_control_selection();

   const char *operation = model_get_operation_name(selected_operation_id);
   if (!operation)
      return;

   int ret = app_control_create(&app_control);
   // Error handling

   ret = app_control_set_operation(app_control, operation);
   // Error handling

   ret = app_control_foreach_app_matched(app_control, app_control_application_matched_cb, NULL);
   // Error handling

   app_control_destroy(app_control);
}

After the call to the app_control_foreach_app_matched() function, the app_control_application_matched_cb() function is called for each installed application that meets the criteria specified by the operation type. On each call to this function, one radio button is added to the popup window.

static bool 
app_control_application_matched_cb(app_control_h app_control, const char *appid, void *user_data)
{
   bool new_radio_group = false;

   if (!view_is_shown_popup_window()) 
   {
      new_radio_group = true;
      // Error handling
   }

   if (view_add_popup_window_radio_button(appid, new_radio_group))
      model_add_application_id(appid);

   view_disable_button(controller_data.viewdata, BUTTON_EXECUTE, EINA_FALSE);

   return true;
}

Once the user has chosen an application from the popup window, the Execute button becomes available. The following code is invoked upon the click event.

The controller_execute() function launches the selected application using the app_control_send_launch_request() function. Note that it also sets some additional operation data using the app_control_add_extra_data() function. This way, if the application supports these data keys, its behavior is altered. For instance, the email application is started in the message creation mode. All the necessary message fields are filled with the defined extra data and the message is ready to be sent.

void 
controller_execute(void)
{
   // Declare the variables

   if (!model_get_app_control_selection(&operation, &appid)) 
   {
      // Error handling
   }

   int ret = app_control_set_operation(controller_data.launch_app_control, operation);
   // Error handling

   ret = app_control_set_app_id(controller_data.launch_app_control, appid);
   // Error handling

   ret = app_control_add_extra_data(controller_data.launch_app_control, APP_CONTROL_DATA_TO, COMPOSE_OP_RECIPIENT);
   if (ret == APP_CONTROL_ERROR_NONE)
      ret = app_control_add_extra_data(controller_data.launch_app_control, APP_CONTROL_DATA_CC, COMPOSE_OP_RECIPIENT_CC);
   if (ret == APP_CONTROL_ERROR_NONE)
      ret = app_control_add_extra_data(controller_data.launch_app_control, APP_CONTROL_DATA_BCC, COMPOSE_OP_RECIPIENT_BCC);
   if (ret == APP_CONTROL_ERROR_NONE)
      ret = app_control_add_extra_data(controller_data.launch_app_control, APP_CONTROL_DATA_SUBJECT, COMPOSE_OP_SUBJECT);
   if (ret == APP_CONTROL_ERROR_NONE)
      ret = app_control_add_extra_data(controller_data.launch_app_control, APP_CONTROL_DATA_TEXT, COMPOSE_OP_MESSAGE);

   // Error handling

   ret = app_control_send_launch_request(controller_data.launch_app_control, __app_control_launch_reply_cb, NULL);
   // Error handling

   view_disable_button(controller_data.viewdata, BUTTON_KILL, EINA_FALSE);
}

Message Composing Area

This sample application gives the user the possibility to compose a message and launch the default email application for the message to be sent. When Send message button is clicked, the following code is executed:

void 
controller_send_message(const char *email_address, const char *email_body)
{
   app_control_h app_control = NULL;

   int ret = app_control_create(&app_control);
   // Error handling

   ret = app_control_set_launch_mode(app_control, APP_CONTROL_LAUNCH_MODE_GROUP);
   // Error handling

   ret = app_control_set_operation(app_control, APP_CONTROL_OPERATION_COMPOSE);
   // Error handling

   ret = app_control_set_app_id(app_control, EMAIL_APP_ID);
   // Error handling

   ret = app_control_add_extra_data(app_control, APP_CONTROL_DATA_TO, email_address);
   // Error handling

   ret = app_control_add_extra_data(app_control, APP_CONTROL_DATA_SUBJECT, EMAIL_DEFAULT_MESSAGE_SUBJECT);
   // Error handling

   ret = app_control_add_extra_data(app_control, APP_CONTROL_DATA_TEXT, email_body);
   // Error handling

   ret = app_control_send_launch_request(app_control, __app_control_launch_reply_cb, NULL);
   // Error handling

   app_control_destroy(app_control);
}