Whenever I connect device it shows "ACTION_ACL_CONNECTED".. But it immediately shows that "ACTION_ACL_DISCONNECTED". I use this code. When any device connect it shows Device Conneted but after sometime it shows Device Disconnected though device is still connected.
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_FOUND.equals(action)) {
Log.e(TAG, "Device found");
//Device found
} else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
Log.e(TAG, "Device is now connected");
//Device is now connected
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
Log.e(TAG, "Done searching");
//Done searching
} else if (BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED.equals(action)) {
Log.e(TAG, "Device is about to disconnect");
//Device is about to disconnect
} else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
Log.e(TAG, "Device has disconnected");
//Device has disconnected
}
}
};
private void registerBluetoothreceiver() {
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);
filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
this.registerReceiver(mReceiver, filter);
}
}