I have a bluetooth device with SPP profile and bluetooth version 2.1.
I have an app which connects to that device and communicates with it. The device uses “Just Works” pairing technique.
I am facing a problem on certain phones like Samsung Galaxy tablet, Galaxy S.
The problem is after the user exits from the app, I am closing the sockets and disconnecting from the device. After successful disconnection, it is observed that the device’s entry is removed from the paired devices list.
I haven’t worked with tablets, but I did write an app that used SPP for Android phones. What I found was that in order to get Bluetooth to be stable, I have to manually bond with the device I want to communicate with. We used the code below to initiated bonding from within the app, and it should preserve the bonding just as if you manually paired through the settings menu.
Here is the general flow:
1) Register a BroadcastReceiver to listen for BluetoothDevice.ACTION_BOND_STATE_CHANGED
2) After device discovery you should have a BluetoothDevice object.
3) Use reflection to call ‘createBond’ method on a BluetoothDeviceObject
3a) Wait for bond state change events before opening sockets
4) Wait for the bond state to change from BOND_BONDING to BOND_BONDED
Inside a BroadcastReciever:
5) Open sockets and communicate
You can also you the ‘removeBond’ method via reflection to remove your device from the pairing list.
Hope this helps!