LaunchOnEventServiceApp Sample Overview

Mobile native

The LaunchOnEventServiceApp sample application demonstrates how you can use launch-on-event in your application.

The LaunchOnEventServiceApp is a service application with no user interface. It is launched by launch-on-event operations. When a launch-on-event operation occurs, a message is shown in the notification window. The operations are earjack connection, USB connection, battery charger connection, and incoming messages.

This service application can be launched by launch-on-event operations when it is not running.

Prerequisites

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

  • http://tizen.org/privilege/message.read

Implementation

To use launch-on-event:

  1. Add an <app-control> element in the tizen-manifest.xml file for each operation that can launch the application:
    • Earjack connection: event://tizen.system.event.earjack_status
    • USB connection: event://tizen.system.event.usb_status
    • Battery charger connection: event://tizen.system.event.battery_charger_status
    • Incoming message: event://tizen.system.event.incoming_msg
    <app-control>
       <operation name=http://tizen.org/appcontrol/operation/launch_on_event/>
       <uri name="event://tizen.system.event.earjack_status"/>
    </app-control>
    <app-control>
       <operation name=http://tizen.org/appcontrol/operation/launch_on_event/>
       <uri name="event://tizen.system.event.usb_status"/>
    </app-control>
    <app-control>
       <operation name=http://tizen.org/appcontrol/operation/launch_on_event/>
       <uri name="event://tizen.system.event.battery_charger_status"/>
    </app-control>
    <app-control>
       <operation name=http://tizen.org/appcontrol/operation/launch_on_event/>
       <uri name="event://tizen.system.event.incoming_msg"/>
    </app-control>
    
  2. Manage the operations:
    1. Register the app_control event callback that is called when the launch-on-event operation launches the application:

      int 
      main(int argc, char* argv[])
      {
         Service_app_lifecycle_callback_s event_callback;
          
         Event_callback.app_control = service_app_control;
      }
      
    2. If the operation is APP_CONTROL_OPERATION_LAUNCH_ON_EVENT, use the URI to determine which launch-on-event operation occurred:

      void 
      service_app_control(app_control_h app_control, void *data)
      {
         char *operation = NULL;
         char *uri = NULL;
         
         ret = app_control_get_operation(app_control, &operation);
      
         if (ret == APP_CONTROL_ERROR_NONE && operation && strncmp(operation, APP_CONTROL_OPERATION_LAUNCH_ON_EVENT, strlen(operation)) == 0)
         {
            ret = app_control_get_uri(app_control, &uri)
      
            if (ret == APP_CONTROL_ERROR_NONE && uri)
            {
               if (strncmp(uri, "event://tizen.system.event.earjack-status", strlen(uri)) == 0)
               {
                  // Earjack is connected
               }
               if (strncmp(uri, "event://tizen.system.event.usb-status", strlen(uri)) == 0)
               {
                  // USB cable is connected
               }
               if (strncmp(uri, "event://tizen.system.event.battery_charger_status", strlen(uri)) == 0)
               {
                  // Battery charger is connected
               }
               if (strncmp(uri, "event://tizen.system.event.incoming_msg", strlen(uri)) == 0)
               {
                  // Incoming message received
               }
            }
         }
      }