Bluetooth Classic Docs

Connection Acceptor

Connection Acceptor

The ConnectionAcceptor is an abstract class that provides the basis for accepting connections from remote peripherals. All ConnectionAcceptor(s) require the BluetoothAdapter and a set of Properties used during connection.

This should have probably been an interface extending Runnable and used that way. But at this point it seems to be working well, and customizable. If things come up where it's required, it can be changed for v2.x.x


protected ConnectionAcceptor(BluetoothAdapter bluetoothAdapter, Properties properties)

Creates an instance of the parent ConnectionAcceptor providing the Android BluetoothAdapter and connection properties.


bluetoothAdapter - the Android BluetoothAdatper

properties - properties used customize how connections are accepted


public void addListener(AcceptorListener<BluetoothSocket> listener)

Provides the ConnectionAcceptor with listener which is notified once a connection is accepted or errored.


listener - the listener to be notified upon successful connection or error


public BluetoothSocket connect(Properties properties)

Accepts to accept connection(s) using the provided properties.


properties - the properties provided during creation


public void cancel()

Attempts to cancel the accepting process.


protected void notifyListeners(BluetoothSocket result)

Notifies the listener of a successful connection, by passing the BluetoothSocket.


result - the successful BluetoothSocket


protected void notifyListeners(Exception e)

Notifies the listener of an error that occurred during the accept attempt.


result - the successful BluetoothSocket


public void run()

Implements the Thread run method. Calls the connect method during processing and either notifies the provided listener of a successful connection (BluetoothSocket) or Exception.


public interface AcceptorListener

The acceptor listener allows the RNBluetoothClassicModule to interact with the accepted connection or handle any errors that might have occurred.


void success(BluetoothSocket socket)

Provides an openned BluetoothSocket to the implementing listener.


socket - the BluetoothSocket which was accepted by the BluetoothServerSocket


void failure(Exception e)

Notifies the implementing listener of a failed accept attempt.


e - the Exception causing the failure


Thread just got left in there from the original implementation

Provides an implemenation of the ConnectionAcceptor which opens a BluetoothServerSocket using rfcomm and the SPP service record. This only accepts a single connection and then returns; if it's found that it would be better to allow multiple connections it can be discussed on the best way in which to perform that.


SECURE_SOCKET - boolean value allowing the selection of listening using a secure or insecure server socket. The default is true.

SERVICE_NAME - the name in which the BluetoothServerSocket will broadcast. The default is RNBluetoothClassic.

Edit this page on GitHub