Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Tizen bluetooth SPP正在接收数据,但发送时BT_错误_权限_被拒绝_Android_C_Bluetooth_Tizen_Tizen Wearable Sdk - Fatal编程技术网

Android Tizen bluetooth SPP正在接收数据,但发送时BT_错误_权限_被拒绝

Android Tizen bluetooth SPP正在接收数据,但发送时BT_错误_权限_被拒绝,android,c,bluetooth,tizen,tizen-wearable-sdk,Android,C,Bluetooth,Tizen,Tizen Wearable Sdk,我正在使用本机Tizen开发一款三星Gear S2,我有一款android应用程序,可以使用SPP作为客户端连接到我的Gear应用程序,android应用程序有一个按钮,用于向我的Gear发送简单文本,这里一切都很好,但当我想从Gear使用SPP向我的android发送数据时,我收到一个BT_错误_权限_拒绝,以下是我的代码摘要: static void socket_connection_state_changed(int result, bt_socket_connectio

我正在使用本机Tizen开发一款三星Gear S2,我有一款android应用程序,可以使用SPP作为客户端连接到我的Gear应用程序,android应用程序有一个按钮,用于向我的Gear发送简单文本,这里一切都很好,但当我想从Gear使用SPP向我的android发送数据时,我收到一个BT_错误_权限_拒绝,以下是我的代码摘要:

static void socket_connection_state_changed(int result,
        bt_socket_connection_state_e connection_state,
        bt_socket_connection_s *connection, void *user_data) {
    appdata_s *ad = (appdata_s *) user_data;

    if (result != BT_ERROR_NONE) {
        dlog_print(DLOG_ERROR, LOG_TAG,
                "[socket_connection_state_changed_cb] Failed. result =%d.",
                result);

        return;
    }

    if (connection_state == BT_SOCKET_CONNECTED) {
        dlog_print(DLOG_INFO, LOG_TAG, "Callback: Connected.");
        if (connection != NULL) {
            dlog_print(DLOG_INFO, LOG_TAG,
                    "Callback: Socket of connection - %d.",
                    connection->socket_fd);
            dlog_print(DLOG_INFO, LOG_TAG, "Callback: Role of connection - %d.",
                    connection->local_role);
            dlog_print(DLOG_INFO, LOG_TAG,
                    "Callback: Address of connection - %s.",
                    connection->remote_address);
            // socket_fd is used for sending data and disconnecting a device
            ad->client_socket_fd = connection->socket_fd;
        } else {
            dlog_print(DLOG_INFO, LOG_TAG, "Callback: No connection data");
        }
    } else {
        dlog_print(DLOG_INFO, LOG_TAG, "Callback: Disconnected.");
        if (connection != NULL) {
            dlog_print(DLOG_INFO, LOG_TAG,
                    "Callback: Socket of disconnection - %d.",
                    connection->socket_fd);
            dlog_print(DLOG_INFO, LOG_TAG,
                    "Callback: Address of connection - %s.",
                    connection->remote_address);
        } else {
            dlog_print(DLOG_INFO, LOG_TAG, "Callback: No connection data");
        }
    }
}

static void bt_socket_data_received_callback(bt_socket_received_data_s* data,
        void* user_data) {
    if (data == NULL) {
        dlog_print(DLOG_INFO, LOG_TAG, "No received data!");

        return;
    }
    dlog_print(DLOG_INFO, LOG_TAG, "Socket fd: %d", data->socket_fd);
    dlog_print(DLOG_INFO, LOG_TAG, "Data: %s", data->data);
    dlog_print(DLOG_INFO, LOG_TAG, "Size: %d", data->data_size);
}

static void start_spp_server(appdata_s *ad) {
    int server_socket_fd = -1;
    const char* my_uuid = "00001101-0000-1000-8000-00805F9B34FB";
    bt_error_e ret;

    ret = bt_initialize();
    if (ret != BT_ERROR_NONE) {
        dlog_print(DLOG_ERROR, LOG_TAG, "[bt_initialize] Failed.");

        return;
    } else {
        dlog_print(DLOG_INFO, LOG_TAG, "[bt_initialize] Success.");
    }

    bt_adapter_state_e adapter_state;

    // Check whether the Bluetooth adapter is enabled
    ret = bt_adapter_get_state(&adapter_state);
    if (ret != BT_ERROR_NONE) {
        dlog_print(DLOG_ERROR, LOG_TAG, "[bt_adapter_get_state] Failed");

        return;
    }
    // If the Bluetooth adapter is not enabled
    if (adapter_state == BT_ADAPTER_DISABLED) {
        dlog_print(DLOG_ERROR, LOG_TAG,
                "Bluetooth adapter is not enabled. You should enable Bluetooth!!");
    }

    ret = bt_socket_set_connection_state_changed_cb(
            socket_connection_state_changed, ad);
    if (ret != BT_ERROR_NONE) {
        dlog_print(DLOG_ERROR, LOG_TAG,
                "[bt_socket_set_connection_state_changed_cb] failed.");

        return;
    }

    ret = bt_socket_set_data_received_cb(bt_socket_data_received_callback,
            NULL);
    if (ret != BT_ERROR_NONE) {
        dlog_print(DLOG_ERROR, LOG_TAG,
                "[bt_socket_data_received_cb] regist to fail.");
    }

    ret = bt_socket_create_rfcomm(my_uuid, &server_socket_fd);
    if (ret != BT_ERROR_NONE) {
        dlog_print(DLOG_ERROR, LOG_TAG, "[bt_socket_create_rfcomm()] failed.");
        log_bt_errors(ret);
    }

    ret = bt_socket_listen_and_accept_rfcomm(server_socket_fd, 5);
    if (ret != BT_ERROR_NONE) {
        dlog_print(DLOG_ERROR, LOG_TAG,
                "[bt_socket_listen_and_accept_rfcomm] failed.");

        return;
    } else {
        dlog_print(DLOG_INFO, LOG_TAG,
                "[bt_socket_listen_and_accept_rfcomm] Succeeded. bt_socket_connection_state_changed_cb will be called.");
        // Waiting for incoming connections
        ad->server_socket_fd = server_socket_fd;
    }
}
最后,我使用一个按钮来测试Gear S2的发送,我使用一个回调来单击按钮,代码如下:

static void clicked_cb(void *data, Evas_Object *obj, void *event_info) {
    dlog_print(DLOG_INFO, LOG_TAG, "Button clicked\n");
    appdata_s *ad = (appdata_s *) data;

    bt_error_e ret;
    char datatosend[] = "Sending test";

    ret = bt_socket_send_data(ad->client_socket_fd, datatosend,
            sizeof(datatosend));
    if (ret != BT_ERROR_NONE) {
        dlog_print(DLOG_ERROR, LOG_TAG, "[bt_socket_send_data] failed.");
        log_bt_errors(ret);
        dlog_print(DLOG_ERROR, LOG_TAG, "las error code = %d", get_last_result());
    }
}

通过调试,我意识到我的发送失败并出现了该错误,我已经在清单中设置了bluetooth权限,可能是什么?

看起来您没有在tizen-manifest.xml文件中添加权限。 所需特权为: 和所需功能:

看起来您没有在tizen-manifest.xml文件中添加权限。 所需特权为: 和所需功能:

谢谢,我没有在清单中设置该功能,但我一直收到拒绝访问错误。谢谢,我没有在清单中设置该功能,但我一直收到拒绝访问错误。