Opening a Client Bluetooth Socket Connection


To initiate a communications channel to a remote device,
create a Bluetooth Socket from the BluetoothDevice object
that represents it.

To create a new connection call createRfcommSocket
ToServiceRecord on the Bluetooth Device to connect to,
passing in the UUID of the Bluetooth Server Socket accepting
requests.

If you attempt to connect to a Bluetooth Device that has
not yet been paired (bonded) with the host device, you will
be prompted to accept the pairing before the connect call    
completes, as shown in Figure

The user must accept the pairing request on both the host
and remote devices for the connection to be
established.



NOTE::
connect is a blocking operation, so it’s best practice to initiate
connection requests on a background thread rather than block the UI thread until a
connection has been made.


Connecting to a remote Bluetooth server


 Try{
      BluetoothDevice device = bluetooth.getRemoteDevice("00:23:76:35:2F:AA");
     BluetoothSocket clientSocket =
    device.createRfcommSocketToServiceRecord(uuid);
    clientSocket.connect();

} catch (IOException e) {
       Log.d("BLUETOOTH", e.getMessage());
}



Comments

Popular posts from this blog

Bluetooth Data Transfer Example

DeCompile .apk file on ubuntu 14.04