Android bluetooth rfcomm connects too slowly

I am creating an unsafe rfcomm connection from my HTC One X to SENA bluetooth ESD110 Serial module with this code:

BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(addr); BluetoothSocket socket = null; try{ socket = device.createInsecureRfcommSocketToServiceRecord(UUID.fromString(SERVICE_UUID)); mBluetoothAdapter.cancelDiscovery(); socket.connect(); sendMessage(socket,"working!"); socket.close(); 

Here you need to connect to the module with automatic parry, and all this works, but it takes about 15 seconds to establish a connection.

Debugging is saved:

 socket.connect(); 

within 15 seconds and only after this connection and transfer of the string to the module (it takes 1 second).

Is it possible that the phone will process some other data (service discovery and more) before connecting to the MAC address and how can I connect it to FASTER? Or could it be a problem with HTC hardware?

+4
source share
2 answers

EDIT , if a slow Discovery service is your problem, you can try to avoid this by skipping all service discovery using the Reflection to createRfcommSocket method directly - I do this for other reasons in my BT-SPP related to the project - it looks like this:

 BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter(); BluetoothDevice bd = bta.getRemoteDevice(mac); Method m = bd.getClass().getMethod("createRfcommSocket",new Class[] { int.class }); bt_connection = (BluetoothSocket) m.invoke(bd, Integer.valueOf(1)); 

Preliminary comment: do you need to constantly scan? If you have the ability to remember mac, you can connect faster. A long wait time imho comes from opening - you can connect only if it is really finished (not executed immediately after mBluetoothAdapter.cancelDiscovery ();) - and this may take some time.

+1
source

Is it faster the second time? Finding your phone for the first time (before your device has the time to assign the target device) takes some time.

However, even if he must find the target, he should not take 15 seconds.

You may have encountered this error: http://code.google.com/p/android/issues/detail?id=29039

Note that there is one situation in which creating a connection works, but takes much longer than usual.

0
source

All Articles