Get more details on applications in the installed package on the device

This snippet will let you get the more details about all applications from a package installed on the device, such as application label, icon path and application type. PRIVILEGE NEEDED: http://tizen.org/privilege/packagemanager.info
#include <stdlib.h>
#include <package_manager.h>
#include <app_manager.h>
#include <dlog.h> //for logging purposes

//callback executed for each app found for package
bool pkginfo_app_cb(package_info_app_component_type_e comp_type, const char *app_id, void *user_data)
{
    LOGI("Application found!");
    app_info_h appinf = NULL;
    if (app_info_create(app_id, &appinf) == PACKAGE_MANAGER_ERROR_NONE)
    {
        char *exec, *label, *icon, *package, *type;
        //Here we can get some info about application
        if (app_info_get_exec(appinf, &exec) == PACKAGE_MANAGER_ERROR_NONE)
        {
            LOGI("app executable path: \t= %s", exec);
        }
        if (app_info_get_label(appinf, &label) == PACKAGE_MANAGER_ERROR_NONE)
        {
            LOGI("app label: \t= %s", label);
        }
        if (app_info_get_icon(appinf, &icon) == PACKAGE_MANAGER_ERROR_NONE)
        {
            LOGI("app icon \t= %s", icon);
        }
        if (app_info_get_package(appinf, &package) == PACKAGE_MANAGER_ERROR_NONE)
        {
            LOGI("app package \t= %s", package);
        }
        if (app_info_get_type(appinf, &type) == PACKAGE_MANAGER_ERROR_NONE)
        {
            LOGI("app type \t= %s", type);
        }

        free(exec);
        free(label);
        free(icon);
        free(package);
        free(type);
        app_info_destroy(appinf);
    }
    return true;
}

//what you should call in the main part of the code
package_info_h pkginfo = NULL;
if (package_info_create("org.tizen.tizenstore", &pkginfo) == PACKAGE_MANAGER_ERROR_NONE)
{
    LOGI("Package found!");
    //Here we execute callback for each app in the package
    int ret = 0;
    ret =  package_info_foreach_app_from_package(pkginfo, PACKAGE_INFO_ALLAPP, pkginfo_app_cb, NULL);
    if (ret != PACKAGE_MANAGER_ERROR_NONE)
    {
        LOGE("package_info_foreach_app_from_package error: %d", ret);
    }
}

Responses

0 Replies