Mobile native Wearable native

Package Manager: Installing and Uninstalling Applications

This tutorial demonstrates how you can retrieve package information and manage packages.

Warm-up

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

Retrieving All Package Information of Installed Packages

To retrieve all package information of installed packages:

  1. To use the functions and data types of the Package Manager API (in mobile and wearable applications):

    1. Include the <package_manager.h> header file in your application:
      #include <package_manager.h>
      
    2. The http://tizen.org/privilege/packagemanager.info, http://tizen.org/privilege/packagemanager.install, and http://tizen.org/privilege/packagemanager.setting privileges are required for the Package Manager API.

      Add the privileges to the tizen-manifest.xml file.

  2. Use the package_manager_foreach_package_info() function:
    package_manager_foreach_package_info(package_info_cb, NULL)
    

    The function takes the following parameters:

    • [in] callback: Callback function to be invoked
    • [in] user_data: User data to be passed to the callback function
    • [out] 0 on success, otherwise a negative error value
  3. Use the package_manager_package_info_cb callback to retrieve all installed packages and print package information. Finally, destroy the package info handler.

    void 
    package_info_cb(package_info_h package_info, void *user_data)
    {
       int ret;
    
       char *pkg = NULL;
       char *label = NULL;
       char *icon = NULL;
       char *version = NULL;
       char *type = NULL;
       package_info_installed_storage_type_e storage;
       bool system;
       bool removable;
       bool preload;
    
       package_info_get_package(package_info, &pkg);
       package_info_get_label(package_info, &label);
       package_info_get_icon(package_info, &icon);
       package_info_get_version(package_info, &version);
       package_info_get_type(package_info, &type);
       package_info_get_installed_storage(package_info, &storage);
       package_info_is_system_package(package_info, &system);
       package_info_is_removable_package(package_info, &removable);
       package_info_is_preload_package(package_info, &preload);
    
       dlog_print(DLOG_INFO, TAG, "pkg \t= [%s]\n", pkg);
       dlog_print(DLOG_INFO, TAG, "label \t= [%s]\n", label);
       dlog_print(DLOG_INFO, TAG, "icon \t= [%s]\n", icon);
       dlog_print(DLOG_INFO, TAG, "version \t= [%s]\n", version);
       dlog_print(DLOG_INFO, TAG, "type \t= [%s]\n", type);
       dlog_print(DLOG_INFO, TAG, "storage \t= [%d]\n", storage);
       dlog_print(DLOG_INFO, TAG, "system \t= [%d]\n", system);
       dlog_print(DLOG_INFO, TAG, "removable \t= [%d]\n", removable);
       dlog_print(DLOG_INFO, TAG, "preload \t= [%d]\n", preload);
    
       free(pkg);
       free(label);
       free(icon);
       free(version);
       free(type);
    }
    
    ret = package_manager_foreach_package_info(package_info_cb, NULL);
    if (ret != PACKAGE_MANAGER_ERROR_NONE) 
    {
       dlog_print(DLOG_ERROR, TAG, "foreach_package_info error : %d", ret);
    }
    

Getting Specific Package Information

To get specific package information:

  1. To use the functions and data types of the Package Manager API (in mobile and wearable applications):

    1. Include the <package_manager.h> header file in your application:
      #include <package_manager.h>
      
    2. The http://tizen.org/privilege/packagemanager.info, http://tizen.org/privilege/packagemanager.install, and http://tizen.org/privilege/packagemanager.setting privileges are required for the Package Manager API.

      Add the privileges to the tizen-manifest.xml file.

  2. Use the package_manager_get_package_info() function:
    package_info_h package_info = NULL;
    package_manager_get_package_info("PACKAGE-ID", &package_info);
    
    // Use package information
    package_info_destroy(package_info);
    

    The function takes the following parameters:

    • [in] package_id: ID of the package
    • [in] package_info: Package information for the given package ID
    • [out] 0 on success, otherwise a negative error value

Listening to Package Events

To detect package events, such as installation, uninstallation, and updates:

  1. To use the functions and data types of the Package Manager API (in mobile and wearable applications):

    1. Include the <package_manager.h> header file in your application:
      #include <package_manager.h>
      
    2. The http://tizen.org/privilege/packagemanager.info, http://tizen.org/privilege/packagemanager.install, and http://tizen.org/privilege/packagemanager.setting privileges are required for the Package Manager API.

      Add the privileges to the tizen-manifest.xml file.

  2. Create the package manager (package_manager_h) using the package_manager_create() function:

    package_manager_h manager;
    package_manager_create(&manager);

    The function takes the following parameters:

    • [in] manager: Package manager handle that is newly created on success
    • [out] 0 on success, otherwise a negative error value
  3. Set the status when the package is installed, uninstalled, or updated:

    package_manager_set_event_status(manager, PACKAGE_MANAGER_STATUS_TYPE_ALL);

    The function takes the following parameters:

    • [in] manager: Package manager handle
    • [in] status_type: Status of the package
    • [out] 0 on success, otherwise a negative error value
  4. Register a callback function to be invoked when the package is installed, uninstalled, or updated:

    package_manager_set_event_cb(manager, event_cb, NULL);
    

    The function takes the following parameters:

    • [in] manager: Package manager handle
    • [in] callback: Callback function to be registered
    • [in] user_data: User data to be passed to the callback function
    • [out] 0 on success, otherwise a negative error value
  5. Implement the package manager event callback:

    void 
    event_cb(const char *type, const char *package, package_manager_event_type_e event_type, 
             package_manager_event_state_e event_state, int progress, 
             package_manager_error_e error, void *user_data)
    {
       if (event_state == PACKAGE_MANAGER_EVENT_STATE_STARTED)
       {
          dlog_print(DLOG_INFO, LOG_TAG, "Started");
       }
       else if (event_state == PACKAGE_MANAGER_EVENT_STATE_PROCESSING)
       {
          dlog_print(DLOG_INFO, LOG_TAG, "Progress : %d", progress);
       }
       else if (event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED)
       {
          dlog_print(DLOG_INFO, LOG_TAG, "Completed");
       }
       else
       {
          dlog_print(DLOG_INFO, LOG_TAG, "Failed");
       }
    }
  6. Free the package manager:

    package_manager_destroy(package_manager_h manager);
Go to top