The Bluetooth library allows you to connect to a Serial Port Profile (SPP) service and exchange data with another Bluetooth enabled device. Your BlackBerry 10 device can act as either an SPP server or SPP client.
Calling bt_spp_deinit() may not be necessary if you have closed all connections. However, there may be situations in which a connection hasn't been cleaned up. In that case, calling bt_spp_deinit() frees all SPP resources your app uses.
To use your device as an SPP client:
#define TEST_SERVICE_UUID "00001101-0000-1111-8888-123456ABCDEF"
bt_remote_device_t **remote_device_array;
bt_remote_device_t *next_remote_device = 0;
char addr[128];
// Initialize the device before calling btdevice functions.
bt_device_init(myCallback);
// Initialize the SPP service
bt_spp_init();
// Get information from a paired remote device
remote_device_array =
bt_disc_retrieve_devices(BT_DISCOVERY_PREKNOWN, 0);
if (remote_device_array) {
// As an example, we'll use the first remote device.
next_remote_device = remote_device_array[0];
bt_rdev_get_address(next_remote_device, addr);
// Open SPP connection to the remote device
int fd = bt_spp_open(addr, (char *)TEST_SERVICE_UUID, false);
if (fd >= 0) {
// Perform desired tasks with the remote device.
// You can exchange data with the remote device using
// the POSIX read() and write() functions.
} else {
// Handle connection error
// ...
}
// Close SPP connection
bt_spp_close(fd);
}
// Free resources
bt_spp_deinit();
bt_device_deinit();