Picking File path workaround

Picking a file path is not documented well, If you want pick a file path use this source.
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);
}

Responses

0 Replies