Ich entwickle ein Samsung Gear S2 mit Native Tizen, ich habe eine Android-App, die als Client mit meiner Gear App verbinden mit SPP, die Android-App haben eine Taste zum Senden von einfachem Text ich erhalte eine BT_ERROR_PERMISSION_DENIED meinem Gang, bei hier gut funktioniert alles, aber wenn ich auf mein android mit SPP von meinem Gang zum senden von Daten wollen, hier ist mein Code zusammengefasst:Tizen Bluetooth SPP Daten empfangen, aber BT_ERROR_PERMISSION_DENIED auf Senden
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;
}
}
Schließlich verwende ich einen Knopf für Test das Senden von meinem Gear S2, benutze ich einen Rückruf für den Button klicken mit diesem Code:
Mit dem Debuggen merke ich, dass mein Senden mit diesem Fehler fehlschlägt, ich habe bereits die Bluetooth-Berechtigung in meinem Manifest gesetzt, was könnte sein?
dank i dont haben diese Funktion in meinem Manifest gefasste, aber ich halte Zugriff verweigert Fehler. –