언어 설정

Menu
Sites
Language
Share text or image to another application (for example, whatsapp,facebook etc.)

Hey,

I have text on the screen and i what to share it to another app. I opened share menu using app control but how to copy text to that application?

Here is my code. Below function opens share menu. But don't know how to copy text to other app after selecting app from share menu(ex. whatsapp,facebook etc.)
I have no idea what to do in share_text_result_cb.

static void
share_btn_text_cb(void *data, Evas_Object *obj, void *event_info)
{
appdata_s *ad=data;
app_control_h app_control;
int ret;

app_control_create(&app_control);
app_control_set_operation(app_control, APP_CONTROL_OPERATION_SHARE);
app_control_set_mime(app_control, "text/plain"); 

ret = app_control_send_launch_request(app_control, share_text_result_cb, ad);

if ( ret == APP_CONTROL_ERROR_NONE)
{
  dlog_print(DLOG_INFO, LOG_TAG, "Succeeded to launch app.");
}
else
{
  dlog_print(DLOG_ERROR, LOG_TAG, "Failed to launch app");
}

app_control_destroy(app_control);
}

 

답변 바로가기

Responses

9 댓글
Sanjeev BA

Hope this helps.

https://developer.tizen.org/development/sample/native/UI/Copy_and_paste

K Johnson

You may try following the way below:

From Sender App: 

Here, _send_data() is a callback registered to a button.

static void
_send_data(void *data, Evas_Object *obj, void *event_info)
{
    app_control_h app_control;

    app_control_create(&app_control);

    app_control_set_operation(app_control, APP_CONTROL_OPERATION_VIEW);
    app_control_set_app_id(app_control, "org.example.basicui2");
    app_control_add_extra_data(app_control, APP_CONTROL_DATA_TEXT, "Hello, World!");

    app_control_send_launch_request(app_control, NULL, NULL);
}

In Receiver App:

Modify app_control() function as below:

static void
app_control(app_control_h app_control, void *data)
{
    /* Handle the launch request. */
    struct appdata *ad = (struct appdata *)data;
    char *operation = NULL;

    app_control_get_operation(app_control, &operation);

    if (!strcmp(operation, APP_CONTROL_OPERATION_VIEW)) {
        int ret;
        char *value;

        ret = app_control_get_extra_data(app_control, APP_CONTROL_DATA_TEXT, &value);
        if (ret == APP_CONTROL_ERROR_NONE)
        {
            dlog_print(DLOG_DEBUG, LOG_TAG, "[value] %s", value);
            elm_object_text_set(ad->label, value);
        }
        else
            dlog_print(DLOG_ERROR, LOG_TAG, "app_control_get_extra_data() failed. err = %d", ret);
    }
}

Hope it'll help you to understand how it's working.

bhoomika rathod

Thank you for answer. But i have one label in my app and i want to share that label to whatsapp ,facebook etc. as text. Is there any other solution for that?

Sanjeev BA

Your label is likely an elm_label or elm_entry. Capture the text in it using elm API.

char share_text[1024]; //for example

_text_copy_cb(void *data, Evas_Object *obj, Elm_Selection_Data *ev)
{
   //get the selected text here
   // store it in your app context for sharing

   // ev parameter has the selected text.
   // the struct members are in this link 

   memcpy(ev->data, share_text, ev->len);
   //share_text has selected text.

}

elm_cnp_selection_get(label_obj, ELM_SEL_TYPE_PRIMARY, ELM_SEL_FORMAT_TEXT, _text_copy_cb, NULL)

 

Whenyou need to share the text use the API mentioned by K Johnson

   //share using
   app_control_add_extra_data(app_control, APP_CONTROL_DATA_TEXT, share_text);

 

Hope this helps.

 

 

Mark as answer
K Johnson

In that case, to share image through an app(i.e. facebook messenger) you may try using the below code snippet. 

app_control_h app_control;
char* data_path = app_get_shared_resource_path(); 

char file_path[PATH_MAX] = {0,};
snprintf(file_path, PATH_MAX, "%s/name_of_image_file.file_extension", data_path);
free(data_path);

app_control_create(&app_control);
app_control_set_operation(app_control, APP_CONTROL_OPERATION_SHARE);
app_control_set_uri(app_control, file_path);
app_control_set_mime(app_control, "image/*"); //you may also use "*/*" instead
app_control_send_launch_request(app_control, NULL, NULL);
app_control_destroy(app_control);

Also please go through Sending Files section of this link for details.

bhoomika rathod

Thank you so much K Johnson  for the solution. 

Dinal Jivani

Thank you K Johnson, I was facing the same problem ,

but another question is how to share the text as a link ?

Dinal Jivani

Thank you K Johnson, I was facing the same problem ,

but another question is how to share the text as a link ?

K Johnson

Unfortunately, I couldn't find any suitable way to share text till now. Please share here if you could manage to do this.