Code example for BluetoothDevice

Methods: createRfcommSocketToServiceRecord

0
            Log.i(TAG, getId() + ":begin mConnectThread");
            BluetoothSocket tmp = null;
            // Always cancel discovery because it will slow down a connection 
 
            try { 
                tmp = mmDevice.createRfcommSocketToServiceRecord(BT_UUID);
            } catch (IOException e) {
                Log.e(TAG, "Socket create() failed", e);
                return; 
            } 
            mmSocket = tmp;
            // Make a connection to the BluetoothSocket 
            if (mAdapter.isEnabled()) mAdapter.cancelDiscovery();
            try { 
                // This is a blocking call and will only return on a 
                // successful connection or an exception 
                if (D)  Log.d(TAG, getId() + ":Connecting to socket...");
                mmSocket.connect();
                if (D) Log.d(TAG, "connected with remote device: "
                        + mmDevice.getName() + " at address " + mmDevice.getAddress());
                connected(mmSocket);