Get all applications in the installed package on the device

This snippet will let you get the information about all applications from a package installed on the device and retrieve and print the executable paths for those apps. PRIVILEGES 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 = NULL;
        //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);
        }
        
        //freeing memory...
        free(exec);
        int ret = PACKAGE_MANAGER_ERROR_NONE;
        ret = app_info_destroy(appinf);
        if (ret != PACKAGE_MANAGER_ERROR_NONE)
        {
            LOGE("app_info_destroy error: %d", ret);
        }
    }
    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 = PACKAGE_MANAGER_ERROR_NONE;
    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