언어 설정

Menu
Sites
Language
How to send a file from wearable to phone over BT

Hi developers!

I have a simple audio recorder applicaiton, and when i stop the recording, I wish to imidietely send the recorded file over BT to my phone.

However I am missing something, and I don't know what.

It's based on sample native ui applicaiton and here is what I've done so far:

 

in

    _app_resume_cb():

i setup the following callbacks:

 

    int error_code = bt_adapter_foreach_bonded_device(bonded_device_cb, NULL);
    dlog_print(DLOG_INFO, LOG_TAG, "bt_adapter_foreach_bonded_device. error code: %s", get_error_message(error_code));

    error_code = bt_socket_set_connection_state_changed_cb(socket_connection_state_changed_cb,NULL);
    dlog_print(DLOG_INFO, LOG_TAG, "registered bt_socket_set_connection_state_changed_cb. error code: %s", get_error_message(error_code));

 

then in my bonded_device_cb() i read the remote_address and service_uuid

 

static bool bonded_device_cb(bt_device_info_s *device_info, void *user_data)
{
    dlog_print(DLOG_INFO, LOG_TAG, "got a bonded device! \n"
            "remote_address: %s \n"
            "remote_name: %s \n"
            "service_uuid: %s \n"
            "is_bonded: %d \n"
            "is_connected: %d \n"
            "is_authorized: %d \n",
            device_info->remote_address,
            device_info->remote_name,
            *device_info->service_uuid,
            device_info->is_bonded,
            device_info->is_connected,
            device_info->is_authorized);
    remote_address = malloc((sizeof(device_info->remote_address)*strlen(device_info->remote_address))+1);
    service_uuid = malloc((sizeof(*device_info->service_uuid)*strlen(*device_info->service_uuid))+1);
    strcpy(remote_address, device_info->remote_address);
    strcpy(service_uuid, *device_info->service_uuid);
    dlog_print(DLOG_INFO, LOG_TAG, "copied!! remote_address: %s, service_uuid: %s", remote_address, service_uuid);
    return true;
}

 

to later use it back in _app_resume_cb() in order to use bt_socket_connect_rfcomm():

 

    dlog_print(DLOG_INFO, LOG_TAG, "remote_address: %s, service_uuid: %s", remote_address, service_uuid);

    error_code = bt_socket_connect_rfcomm(remote_address, service_uuid);
    dlog_print(DLOG_INFO, LOG_TAG, "bt_socket_connect_rfcomm. error code: %s", get_error_message(error_code));

 

so the connection error_code is successful, and in my socket_connection_state_changed_cb() i read the socket_fd:

static void socket_connection_state_changed_cb(int result, bt_socket_connection_state_e connection_state,
                                                bt_socket_connection_s *connection, void *user_data)
{
    dlog_print(DLOG_INFO, LOG_TAG, "socket connection state changed \n"
            "result: %s "
            "connection_state: %d "
            "socket_fd: %d "
            "server_fd: %d "
            "remote_address: %s "
            "local_role: %d "
            "service_uuid: %s ",
            get_error_message(result),
            connection_state,
            connection->socket_fd,
            connection->server_fd,
            connection->remote_address,
            connection->local_role,
            connection->service_uuid);

    socket_fd = connection->socket_fd;
}

 

to then use in sending data using bt_socket_send_data(). I send the data after pressing the stop record button:

 

...
/* Stop the recorder and save the recorded data to a file */
        if (_recorder_expect_state(g_recorder, RECORDER_STATE_RECORDING)
                || _recorder_expect_state(g_recorder, RECORDER_STATE_PAUSED))
        {
            char *filez;
            recorder_get_filename(g_recorder, &filez);

            stop_recorder();
            dlog_print(DLOG_INFO, LOG_TAG, "stopped recording");
            Eina_Bool shared = EINA_FALSE;
            Eina_File * ein_file = eina_file_open(filez, shared);
            size_t fil_size = eina_file_size_get(ein_file);
            const char * fil_name = eina_file_filename_get(ein_file);
            dlog_print(DLOG_INFO, LOG_TAG, "****opened file?, filez: %s fil_size: %d, fil_name: %s", filez, fil_size, fil_name);
            error_code = bt_socket_send_data(socket_fd, data, fil_size);
            dlog_print(DLOG_INFO, LOG_TAG, "****sending file!!!!! number of bytes written: %d", error_code);
...

 

and in the logs i can see the file name and size printed correctly.

some logs printouts:

got a bonded device!  remote_address: 34:2D:0D:12:BB:89  remote_name: Galaxy S8  service_uuid: 00001105-0000-1000-8000-00805F9B34FB  is_bonded: 1  is_connected: 1  is_authorized: 0 
socket connection state changed  result: Successful connection_state: 0 socket_fd: 40 server_fd: -1 remote_address: 34:2D:0D:12:BB:89 local_role: 2 service_uuid: 00001105-0000-1000-8000-00805F9B34FB 
...
remote_address: 34:2D:0D:12:BB:89, service_uuid: 00001105-0000-1000-8000-00805F9B34FB
bt_socket_connect_rfcomm. error code: Successful
...
****opened file?, filez: /opt/usr/media/Documents/AUDIO_2019_12_12_18_39_27.3gp fil_size: 835, fil_name: /opt/usr/media/Documents/AUDIO_2019_12_12_18_39_27.3gp
****sending file!!!!! number of bytes written: 835

 

On the phone I never get request to "receive a file", unless it's done "silently"? in which i doubt highly. I tried to search for the file manually but to no avail.

Please tell me what am I missing!

 

Best regards,

Adam

 

Responses

4 댓글
Slawek Kowalski

To get a file on phone you have to use OBEX profile. This profile is not supported on werable devices.

However, API is available. Now you try to send data by SPP (Serial Port Profile). You must write SPP Server on phone side to

handle this connection.

 

Adam Kramarczyk

But..How does that make any sense? Thats nosense... So I have a recorder application, and I need to write 2 more applications to send a single file over BT? Thats just plain stupid. How come there are paid applications that do all of this in ONE single application without requiring to install any other apps on the phone?

Slawek Kowalski

Using socket connection you just sending raw data chunk not a file. 

Slawek Kowalski

You can use this tool:  https://forum.developer.samsung.com/t/app-handler-for-tizen-operations-share-share-multi-pick/1913