Mobile native Wearable native

Application Manager: Getting Information about Applications

This tutorial demonstrates how you can get information about applications.

Warm-up

Become familiar with the Application Manager API basics by learning about:

Managing the Application Context

To get the running application context and its details, and to operate on the context:

  1. To use the functions and data types of the Application Manager API (in mobile and wearable applications), include the <app_manager.h> header file in your application:

    #include <app_manager.h>
    
  2. Get the context of the currently running application.

    When an application is not running, it is impossible to get its context.

    Call the app_manager_get_app_context() function with the ID of the application from which the context is being obtained, and the handle (app_context_h*) to the application context which is filled with the received context:

    app_context_h app_context = NULL;
    
    int ret = app_manager_get_app_context(Your App ID, &app_context);
    

    This example gets for the context of the Clock application. If the function returns APP_MANAGER_ERROR_NONE, it has executed correctly and the app_context variable now contains the handle to the clock context. To prevent memory leaks, release app_context with the app_context_destroy() function after the work is finished.

  3. Operate on the context:
    • Get the application ID and application process ID from the context:
      char *app_id;
      int pid = 0;
      
      ret = app_context_get_app_id(app_context, &app_id);
      ret = app_context_get_pid(app_context, &pid);
      

      When app_id is no longer needed, release it using the free() function.

    • Check whether the application with the given application context is terminated:

      bool terminated = false;
      
      ret = app_context_is_terminated(app_context, &terminated);
      
      if (false == terminated)
      {
         // Application is running
      } 
      else 
      {
         // Application is terminated
      }
      
    • Clone the given context handle:

      app_context_h app_context_cloned = NULL;
      
      ret = app_context_clone(&app_context_cloned, app_context);
      
    • Check whether 2 contexts are equal:

      bool equal = false;
      
      ret = app_context_is_equal(app_context, app_context_cloned, &equal);
      
      if (equal)
      {
         // Contexts are equal
      } 
      else 
      {
         // Contexts are not equal
      }
      
  4. When working with the application context is finished, call the app_context_destroy() function to remove the handle and release all resources:

    if (app_context) 
    {
       ret = app_context_destroy(app_context);
       if (APP_MANAGER_ERROR_NONE != ret) // Error handling 
          app_context = NULL;
    }
    

Getting Information on Filtered Applications

To get information on filtered applications:

  1. To use the functions and data types of the Application Manager API (in mobile and wearable applications), include the <app_manager.h> header file in your application:

    #include <app_manager.h>
    
  2. Create the app_info_filter_h handle using the app_info_filter_create() function:
    app_info_filter_h app_info_filter = NULL;
    
    int ret = app_info_filter_create(&app_info_filter);
    
  3. Add filter rules:
    ret = app_info_filter_add_string(app_info_filter, PACKAGE_INFO_PROP_APP_TYPE, "capp");
    
  4. Use the app_info_filter_cb() callback to retrieve all filtered applications and print their information:
    void app_info_filter_cb(app_info_filter_h app_info, void *user_data)
    {
       int ret;
    
       char *app_id = NULL;
    
       app_info_get_app_id(app_info, &app_id);
    
       dlog_print(DLOG_INFO, TAG, "app_id \t= [%s]\n", app_id);
    
       free(app_id);
    }
    
    ret = app_info_filter_foreach_appinfo(app_info_filter_cb, NULL);
    if (ret != APP_MANAGER_ERROR_NONE)
    {
       dlog_print(DLOG_ERROR, TAG, "foreach_app_info_filter error : %d", ret);
    }
    
  5. When you no longer need the filter, call the app_info_filter_destroy() function to remove the handle and release all resources:
    if (app_info_filter_h)
    {
       ret = app_info_filter_destroy(app_info_filter_h);
       if (APP_MANAGER_ERROR_NONE != ret) // Error handling
          app_info_filter_h = NULL;
    }
    
Go to top