Get application metadata

As an app developer you can add your own metadata - key/value pairs to the app manifest (it can be set using Tizen Manifest Editor, "Advanced" tab). This snippet lists all metadata found in all the apps from a requested package. PRIVILEGE NEEDED: http://tizen.org/privilege/packagemanager.info
#include <package_manager.h>
#include <app_manager.h>
#include <dlog.h> //for logging purposes

//callback executed for each key/value metadata pair found in the application
bool metadata_cb(const char *metadata_key, const char *metadata_value, void *user_data)
{
    LOGI("INFO Metadata key found: %s, value: %s", metadata_key, metadata_value);
    return true;
}

//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)
    {
        //Here we can look for application metadata
        if (app_info_foreach_metadata (appinf, metadata_cb, NULL) == PACKAGE_MANAGER_ERROR_NONE)
        {
            LOGI("Looking for application metadata");
        }
        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