简体   繁体   English

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

[英]How to send a file from Tizen wearable to Android phone over BT

I have a simple audio recorder application, and when I stop the recording, I wish to immediately send the recorded file over bluetooth to my phone.我有一个简单的录音机应用程序,当我停止录音时,我希望立即通过蓝牙将录制的文件发送到我的手机。

However I am missing something, and I don't know what.但是我错过了一些东西,我不知道是什么。

It's based on sample native ui application written in C and here is what I've done so far:它基于用 C 编写的示例本机 ui 应用程序,这是我迄今为止所做的:

in _app_resume_cb(): I setup the following callbacks:_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));

then in my bonded_device_cb() I read the remote_address and service_uuid然后在我的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;
}

to later use it back in _app_resume_cb() in order to use bt_socket_connect_rfcomm() :稍后在_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));

so the connection error_code is successful, and in my socket_connection_state_changed_cb() I read the socket_fd :所以连接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;
}

to then use in sending data using bt_socket_send_data() .然后使用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've tried to search for the file manually but to no avail.我尝试手动搜索该文件,但无济于事。

Please tell me what am I missing!请告诉我我错过了什么!

Best regards,此致,

Helban赫尔班

To send the specific file to the remote device, you should use 'OPP client' API instead of RFCOMM socket client API.要将特定文件发送到远程设备,您应该使用“OPP 客户端”API 而不是 RFCOMM 套接字客户端 API。 RFCOMM API is just sending the message. RFCOMM API 只是发送消息。 Maybe,, Android's socket server received "FileName" string only.也许,Android 的套接字服务器只收到“FileName”字符串。

Can you use next code in bt_socket_connect_rfcomm API calling position?您可以在 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);

But unfortunately, 'Tizen Wearable' does not support "OPP" feature.但遗憾的是,“Tizen Wearable”不支持“OPP”功能。 (The specific daemon for OPP is not included maybe, so next OPP feature will be false) (可能不包括 OPP 的特定守护程序,因此下一个 OPP 功能将是错误的)

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

That means, even if you modified the code as above.这意味着,即使您如上所述修改了代码。 The API will return "Not Supported". API 将返回“不支持”。

** In now, there is no way to enable the feature in the released product. ** 目前,在发布的产品中无法启用该功能。

Even though you can't use Native BT OPP API caused of the feature limitation, you can use the companion APIs.即使由于功能限制而无法使用 Native BT OPP API,您也可以使用配套的 API。 (SAP API) (SAP API)

You can refer and get the full information for it in next URL.您可以在下一个 URL 中参考并获取它的完整信息。 https://developer.samsung.com/galaxy-watch/develop/samples/companion/file-native https://developer.samsung.com/galaxy-watch/develop/samples/companion/file-native

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用本机Tizen可穿戴设备中的libcurl从URL输出json响应 - Output json response from url using libcurl in Native Tizen wearable Tizen 原生可穿戴设备 - 如何添加文本标签自动换行符? - Tizen native wearable - how to add text label auto line break? 双击事件在 Tizen 可穿戴设备中不起作用? 为什么? - Double click event doesn't work in Tizen wearable? Why? 为什么我在 Tizen Native Wearable 中得到恒定的步数? - Why am i getting constant step count in Tizen Native Wearable? 登录到 Tizen 中的特定文件? - Logging into a specific file in Tizen? Tizen蓝牙SPP接收数据,但发送时BT_ERROR_PERMISSION_DENIED - Tizen bluetooth SPP receiving data but BT_ERROR_PERMISSION_DENIED on sending 如何在 Tizen Native 中从手表打印心率和步数数据? - How to print heart rate and stepcount data from the watch in Tizen Native? 我如何通过蓝牙低功耗从类型 %8.5f 发送两个字节的浮点数到我的 android 应用程序 - How can I send with two bytes a float from type %8.5f over bluetooth low energy to my android app 如何在C中通过网络分段发送二进制文件? - How send a binary file in segments over network in C? 在 Tizen Native Wearable App (Samsung G3) 的模板中,我可以开始将代码放入哪一行 - Which line can I start to put my code in, in template for Tizen Native Wearable App (Samsung G3)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM