I work with a bluetooth device (IOIO development panel).
I want to listen when my device is turned off. It works fine with the code above, but it is not recognized instantly. When I turn off my bluetooth development panel, I need to wait ~ 16 seconds until my Android finds out that the connection has been lost.
Does anyone know why? I heard that this should be Android's internal limitation, that the connection is not checked so often? Does anyone know how to write a stream that “connects” a bluetooth device if it is still there? I think this is very similar to the Android BluetoothChat example, but I could not fix it myself.
Thank.
Felix
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
IntentFilter filter1 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);
IntentFilter filter2 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED);
this.registerReceiver(mReceiver, filter1);
this.registerReceiver(mReceiver, filter2);
}
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED.equals(action)) {
Toast.makeText(context,"The device is about to disconnect" , Toast.LENGTH_LONG).show();
}
else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
Toast.makeText(context,"Device has disconnected" , Toast.LENGTH_LONG).show();
}
}
};