I'm trying to build an apk that will disconnect Bluetooth headphones when I press a button. I'm able to get the names and the mac addresses of the connected Bluetooth devices but I don't have a clue what will be the command to disconnect/connect the device. I was looking for something that uses the mac address of the paired device but I can't find anything.
Help will be appreciated.
I have tried this code here
public void disConnectDevice(String address) {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address);
BluetoothGatt mBluetoothGatt = device.connectGatt(this, false, gattCallback);
mBluetoothGatt.disconnect();
}
private BluetoothGattCallback gattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
gatt.close();
}
};
but unfortunately, I can't make it work. It does nothing and I don't understand exactly what it is supposed to do.