Languages

Menu
Sites
Language
File Picker

Hi, I am porting a Nintendo Gameboy Color emulator. I want to provide the users the option to pick a ".gb" or ".gbc" file. The "clicked" callback of the button and the result callback of app control looks like this.

static void app_control_result(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
{
    char *value;
    if(result == APP_CONTROL_RESULT_SUCCEEDED)
    {
        int ret = app_control_get_extra_data(reply, APP_CONTROL_DATA_PATH, &value);
        if ( ret == APP_CONTROL_ERROR_NONE)
        {
            dlog_print(DLOG_INFO, LOG_TAG, "[app_control_extra_data_cb] Succeeded: value(%s)", value);
        }
        else
        {
            dlog_print(DLOG_ERROR, LOG_TAG, "[app_control_extra_data_cb] Failed: Error code: %d", ret);
        }
    }
    else
    {
        dlog_print(DLOG_ERROR, LOG_TAG, "[app_control_result_cb] APP_CONTROL_RESULT_FAILED. Error code: %d", result);
    }
}



void clicked_cb(void *data, Evas_Object *obj, void *event_info)
{
    appdata_s *ad = data;


    app_control_h app_control;
    app_control_create(&app_control);
    app_control_set_operation(app_control, APP_CONTROL_OPERATION_PICK);
    app_control_send_launch_request(app_control, app_control_result, ad);
    app_control_destroy(app_control);
}

Picking a file with the built in file explorer I get : [app_control_extra_data_cb] Failed: Error code: -126

I have added mediastorage, externalstorage and other data related privileges in the manifest file. What am I doing wrong?

Edited by: HM Mehrab on 10 Aug, 2015
View Selected Answer

Responses

9 Replies
Jean Yang

I do not see the calling for app_control_add_extra_data() before your call app_control_send_launch_request().

Inside app_control_result(), you called app_control_get_extra_data() to get the extra data, but you have not passed in your extra data at all.

So, please call app_control_add_extra_data() firstly before you call app_control_send_launch_request().

Jean Yang

Here is the tutorial you can reference:

https://developer.tizen.org/development/tutorials/native-application/application-framework/application

And the example at section: Running Applications Using Extra Data.

For the file you want to pick, you may need following reference for filesystem:

https://developer.tizen.org/development/tutorials/web-application/tizen-features/inputoutput/filesystem

colin Rao

Hi,

[app_control_extra_data_cb] Failed: Error code: -126.

TIZEN_ERROR_KEY_NOT_AVAILABLE = -ENOKEY, /**< Required key not available */

#define    ENOKEY        126    /* Required key not available */

As your sample code, 

int ret = app_control_get_extra_data(reply, APP_CONTROL_DATA_PATH, &value);

-126 means there isn't extra dat key APP_CONTROL_DATA_PATH.

 

I've ever encounter such issue, in my case,  the key is "path",

ret = app_control_get_extra_data(reply, "path", &value);

 

HM Mehrab

Notice that I am using app_control_get_extra_data() on the reply app control, which is supposed to be filled by the application that was called to do the task. In this case, I am opening a file browser and that file browser is supposed to return to me the path of the file selected by the user. That is what I understood. What am I supposed to send as extra data to the file browser? 

HM Mehrab

@Colin

I have tried using "path" as the key, but still did not get the path. Seems like "path" only works for img MIME types.

colin Rao

Hi,

Yes, my case is to open a browser to select an image.

Try more, to foreach all the keys on reply handler.

app_control_foreach_extra_data(reply, foreach_extra_data_cb, NULL);
static bool
foreach_extra_data_cb(app_control_h app_control, const char *key, void *user_data)
{
    char *value;
    int ret;

    ret = app_control_get_extra_data(app_control, key, &value);
    if ( ret == APP_CONTROL_ERROR_NONE)
    {
        dlog_print(DLOG_INFO, LOG_TAG, "[app_control_extra_data_cb] Succeeded: key(%s), value(%s)", key, value);
    }
    else
    {
        dlog_print(DLOG_ERROR, LOG_TAG, "[app_control_extra_data_cb] Failed: key(%s), Error code: %d", key, ret);
        return FALSE;
    }
    return TRUE;
}

 

HM Mehrab

I get a single line:

[app_control_extra_data_cb] Failed: key(http://tizen.org/appcontrol/data/selected), Error code: -126

Mark as answer
pius lee

Can you try it?

There are no document or spec for picking file. so we should be prepared for array reply or not.

static void ac_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
{
    appdata_s *ad = user_data;
	if (result == APP_CONTROL_RESULT_FAILED ) {
		LOGI("app control failed");
		return;
	}
	if (result == APP_CONTROL_RESULT_CANCELED) {
		LOGI("app control canceled");
		return;
	}

	bool is_array;
	app_control_is_extra_data_array(reply, "path", &is_array);

	ad->path[0] = '\0';
	if (is_array) {
		int i, count = 0;
		char **paths = NULL;
		app_control_get_extra_data_array(reply, "path", &paths, &count);

		if (paths != NULL) {
			for(i=0; i<count; i++) {
				LOGI("file selected : %s", paths[i]);
			}
			if (count > 0) strcpy(ad->path, paths[0]);
			for(i=0; i<count; i++) free(paths[i]);
			free(paths);
		} else {
			LOGI("file select failed!");
		}
	} else {
		char *path = NULL;
		app_control_get_extra_data(reply, "path", &path);
		if (path != NULL) strcpy(ad->path, path);
		else LOGI("file select failed!");
		free(path);
	}
	LOGI("file selected : %s", ad->path);
}

static void btn_clicked(void *data, Evas_Object *obj, void *event_info)
{
	appdata_s *ad = data;
	app_control_h ac;
	app_control_create(&ac);
	app_control_set_operation(ac, APP_CONTROL_OPERATION_PICK);
	app_control_send_launch_request(ac, ac_cb, ad);
	app_control_destroy(ac);
}

 

HM Mehrab

That woked like a charm. Thanks a lot man. I was giving up hope. Marked as the answer :D