如何通过BT将可穿戴设备的Tizen文件发送到Android手机

问题描述 投票:0回答:3

我有一个简单的音频记录器应用程序,当我停止记录时,希望立即通过蓝牙将记录的文件发送到手机。

但是我缺少什么,我也不知道。

它基于用C编写的示例本机ui应用程序,这是我到目前为止所做的:

_app_resume_cb():中我设置了以下回调:

    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));

然后在我的bonded_device_cb()中,我阅读了remote_addressservice_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;
}

稍后再在_app_resume_cb()中使用它以便使用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));

所以连接error_code成功,并且在我的socket_connection_state_changed_cb()中读取了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;
}

然后用于通过bt_socket_send_data()发送数据。我按下停止记录按钮后发送数据:

...
/* 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);
...

并且在日志中,我可以看到正确打印的文件名和大小。

某些日志打印输出:

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

除非在电话中我是“默默地”完成的,否则我从不会收到“接收文件”的请求?我对此表示高度怀疑。我尝试手动搜索文件,但无济于事。

请告诉我我在想什么!

最诚挚的问候,

Helban

c bluetooth tizen tizen-wearable-sdk tizen-native-app
3个回答
0
投票

要将特定文件发送到远程设备,应使用“ OPP客户端” API而不是RFCOMM套接字客户端API。 RFCOMM API只是发送消息。也许,Android的套接字服务器仅收到“ FileName”字符串。

您可以在bt_socket_connect_rfcomm API调用位置使用下一个代码吗?

static void _adapter_opp_client_push_responded_cb(int result, const char *remote_address, void *data)
{
        DBG(" _adapter_opp_client_push_responded_cb ");

}

static void _adapter_opp_client_push_progress_cb(const char *file, long long size, int percent, void *data)
{
        DBG(" _adapter_opp_client_push_progress_cb ");

}

static void _adapter_opp_client_push_finished_cb(int result, const char *remote_address, void *data)
{
        DBG(" _adapter_opp_client_push_finished_cb ");

}


result = bt_opp_client_initialize();

result = bt_opp_client_add_file(get_shared_resource_path(this->view->tbt_info->file_name));

result = bt_opp_client_push_files(this->selected_device_info->remote_address, _adapter_opp_client_push_responded_cb, _adapter_opp_client_push_progress_cb, _adapter_opp_client_push_finished_cb, this);

0
投票

但是很遗憾,“ Tizen可穿戴式”不支持“ OPP”功能。 (可能不包括OPP的特定守护程序,因此下一个OPP功能将为false)

https://www.tizen.org/feature?langredirect=1-> http://tizen.org/feature/network.bluetooth.opp

这意味着,即使您如上所述修改了代码。 API将返回“不支持”。

**目前,无法在已发布的产品中启用该功能。


0
投票

即使由于功能限制而无法使用本机BT OPP API,也可以使用随附的API。 (SAP API)

您可以在下一个URL中引用并获取其完整信息。https://developer.samsung.com/galaxy-watch/develop/samples/companion/file-native

© www.soinside.com 2019 - 2024. All rights reserved.