I have the following android code which creates a Bluetooth connection to a remote device. Is there any way to find that the remote device has gone out of range?
private void connectToRobot(BluetoothDevice bd){
try{
Method m = bd.getClass().getMethod("createRfcommSocket",
new Class[] {int.class});
socket = (BluetoothSocket) m.invoke(bd, 1);
socket.connect();
Toast.makeText(AndroidBluetooth.this,"CONNECTED ",
Toast.LENGTH_LONG).show();
os = socket.getOutputStream();
}catch (Exception e){
Log.e(tag,"Error interacting with remote device [" +
e.getMessage() +"]");
}
}
The only information I can get now is whether the BluetoothSocket succeeds or not. Is there a way to determine the strength of the connection?
I am unaware of any functions to be able to determine if a device is out of range or if it has just been disconnected by the user, however one thing that you could do would be to monitor the RSSI and if it decreases before disconnecting, call it out of range. If it has a string signal when it disconnects, call it disconnected by user.