The project is to use my android phone to connect with my arduino devices. but how can I unpair the paired ones. I see it seems the paired list is stored where bluetoothadapter could retrieve anytime.
PS: 1st, I know long press paired device will unpair it.
but the question here is how can I make this happen programmatically?
2nd, I have checked bluetoothdevice and bluetoothAdapter class, there is no function to implement this.
thanks.
Using Android Bluetooth API, we can use createBond method to pair with a device or removeBond to unpair. This is an asynchronous call so that it will return immediately. To catch the pairing process, we have to register a BroadcastReceiver with ACTION_BOND_STATE_CHANGED intent to catch the process.
1 From a Home screen, do one of the following: Ensure Bluetooth is turned on. Navigate: Settings > Connected devices > Connection preferences > Bluetooth. Navigate: Settings > Connected devices. ... 2 Tap the appropriate device name or the Settings icon (right). 3 Tap 'Forget' or 'Unpair'.
Navigate: Settings > Connected devices > Connection preferences > Bluetooth. Navigate: Settings > Connected devices. If necessary, tap Bluetooth. Navigate: Settings > Bluetooth. Tap the appropriate device name or the Settings icon (right). Tap 'Forget' or 'Unpair'.
1 Open the Settings 2 Tap on Connections 3 Tap on Bluetooth 4 Open the Settings of paired device 5 Tap on Unpair
I have requirement to unpair or remove bonding for paired device. Could not find any API to unpair device in Android.Bluetooth->BluetoothDevice. Using Android Bluetooth API, we can use createBond method to pair with a device or removeBond to unpair. This is an asynchronous call so that it will return immediately.
This code works for me.
private void pairDevice(BluetoothDevice device) { try { if (D) Log.d(TAG, "Start Pairing..."); waitingForBonding = true; Method m = device.getClass() .getMethod("createBond", (Class[]) null); m.invoke(device, (Object[]) null); if (D) Log.d(TAG, "Pairing finished."); } catch (Exception e) { Log.e(TAG, e.getMessage()); } } private void unpairDevice(BluetoothDevice device) { try { Method m = device.getClass() .getMethod("removeBond", (Class[]) null); m.invoke(device, (Object[]) null); } catch (Exception e) { Log.e(TAG, e.getMessage()); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With